i have a dropdown box and i already upload the value from dropdown selection to database. after uploading i want to cange the dropdown value how should i do,please help me.
thanks in advance
i have a dropdown box and i already upload the value from dropdown selection to database. after uploading i want to cange the dropdown value how should i do,please help me.
thanks in advance
Show your code so far and give and example of what you want to see.
this code is to upload values to database table.
<select id="city" name="city" onChange="getPlace(this.value)">
<option value="" selected="selected">... Select City ...</option>
<?php
include("db.php");
$query = "SELECT `state_id`, `state` FROM `states` ";
$result = mysql_query($query);
//echo mysql_error();
while($rows = mysql_fetch_array($result))
{
$selected = "";
$categoryId = $rows['state_id'];
$categoryName = $rows['state'];
if($catid == $categoryId)
{
$selected = "selected";
}
?>
<option value="<?php echo $categoryId; ?>" <?php echo $selected; ?> ><?php echo $categoryName; ?></option>
<?php } ?>
</select>
<div align="left" id="citydiv">
and javascript to display checkbox value
function getPlace(stateId) {
var strURL="findplace.php?city="+stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
findplace.php
<? $city=intval($_GET['city']);
include("db.php");
$query="SELECT `city_id`, `city` FROM `cities` WHERE `state_id`='$city'";
$result=mysql_query($query);
?>
<td><div align="left">Place:</div></td><td>
<? while($row=mysql_fetch_array($result)) { ?>
<input type="checkbox" name="place[]" value="<?=$row['city_id']?>" /><?=$row['city']?>
<? } ?>
$lid= mysql_insert_id();
//cityid and placeid added here
$cityid = trim(ucwords(strtolower(mysql_real_escape_string($_POST['city']))));
$num=count($_POST["place"]);
foreach($_POST["place"] as $i=>$value)
{
$value=$_POST["place"][$i];
$sql3 = mysql_query("INSERT INTO `city_place`(`city_id`, `place_id`, `spaid`) VALUES ('$cityid','$value',$lid)");
}
after uploading in edit page i want to show the selected value in dropdown selection and checkbox selected value only,then if i want to change the selected value i should select from dropdown and checkbox
When you Use update query at that time execute select query and result pass to select box using ajax
i have no idea about update values in dropdownbox and checkbox. above i have added insert query to database. so please guide me. i tried but am not getting exactly.where i have to add ajax call function and how to use it for selected cities and also non selected cities in checkbox based on dropdown menu selection. in dropdown menu i want to show only one city and in checkbox to show both selected and non selected cities.
<?php $sql3 = mysql_query("SELECT s.id,cp.`id`, cp.`state_id`, cp.`city_id`, cp.`spaid`,c.city,st.state FROM spa s
LEFT JOIN `city_place` cp ON cp.spaid=s.id
LEFT JOIN states st ON st.state_id=cp.state_id
LEFT JOIN cities c ON c.city_id=cp.city_id
WHERE s.id='$id' LIMIT 0,1");
while($c = mysql_fetch_array($sql3))
{
?>
<tr><td>City: </td><td><select name="city" id="city" onChange="getPlace(this.value)">
<option value="" selected="selected"><?php echo $c['state']; ?></option>
</select>
<?php } ?>
<tr><td><div id="placediv">
<ul class="subcat_tick">
<? while($row = mysql_fetch_array($sql11))
{
$state_id = $row['state_id'];
$city_id = $row['city_id'];
$checked = (is_null($city_id)) ? '' : " checked"; ?>
<li>
<input name='place[$state_id]' type='checkbox'$checked /> <span><?=$row['city']?></span>
</li>
<? } ?>
</ul>
</div></td></tr>
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.