I have a drop down that is automatically generated using PHP, and basically what I need to happen is on selection of a ceratin one to go to the database and check the latest id associated with that category and the use that ID add 1 to it, and then when the user updates the database, the new ID is associated with that entry.
I was htinking that AJAX might be the best option for it.
Here is what I got so far.
<
select name="txtdesc">
<?php $qw=mysql_query("select DISTINCT(Desc_Ame), Id_Ame from tbl_amenities group by Desc_Ame") or die (mysql_error());
while($r=mysql_fetch_assoc($qw))
{
if($r['Desc_Ame']==$desc)
{
echo "<option value='$r[Desc_Ame]' selected>$r[Desc_Ame]</option>";
}
else
{
echo "<option value='$r[Desc_Ame]'>$r[Desc_Ame]</option>";
}
}
?>
OK I found an idea and am trying to apply it to this job, and what I thought would happen isnt, so I’m missing something somewhere.
<script type="text/javascript">
function showUserGroup(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
else
// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
xmlhttp.open("GET","getusergroup.php?q="+str,true);
xmlhttp.send();
}
</script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript">
$('[name="form1"]').on('change', function() {
var ajaxMethod = "admin_amenties.php";
switch($(this).val())
{
case "General":
ajaxMethod = "stuff 1";
break;
case "Rooms":
ajaxMethod = "stuff 2";
break;
case "Services":
ajaxMethod = "stuff 3";
break;
case "Meeting":
ajaxMethod = "stuff 4";
break;
case "Accessibility":
ajaxMethod = "stuff 5";
break;
}
$("#txtHint b").load(ajaxMethod);
});​
</script>
<form action="admin_amenties.php?index=<?=$index?>" method="post" name="form1" onchange="showUserGroup(this.value)">
<select name="txtdesc">
<?php $qw=mysql_query("select DISTINCT(Desc_Ame), Id_Ame from tbl_amenities group by Desc_Ame") or die (mysql_error());
while($r=mysql_fetch_assoc($qw))
{
if($r['Desc_Ame']==$desc)
{
echo "<option value='$r[Desc_Ame]' selected>$r[Desc_Ame]</option>";
}
else
{
echo "<option value='$r[Desc_Ame]'>$r[Desc_Ame]</option>";
}
}
?>
</select>
<div id="txtHint"></div>
</form>
It looks like you are inappropriately loading jQueryUI.
What should work much better for you here it to load up the jQuery library instead.