Hoping somebody can help me with this. For some reason, the following form code always gives the ‘route’ radio button value as being ‘m’, even when the the option with value ‘s’ is selected.
echo "<b><u>Route Information</u></b><br><br>";
echo "Select Route Name: <input type='radio' name='route' id='route1' value='s' onclick='switchRoute();' CHECKED><br>";
echo "<div id='txtLocation'><select name='route_name' id='route_name'>
<option value='0000'>... select a location ...</option>";
echo "</select></div><br><br>";
echo "Or enter a new route (select the radio button for this option):<input type='radio' name='route' id='route2' value='m' onclick='switchRoute();'><br>";
echo "    Route Name:<br>    <input name='new_route_name' size='50' disabled='true' class='input-xlarge'><br><br>";
echo "    Route Grade:<br>    <input type='number' name='route_grade' class='input-mini' disabled='true'><br><br>";
echo "    Route Description <i>(optional)</i>:<br>    <textarea name='route_description' class='input-xxlarge' rows='3' disabled='true'></textarea><br><br>";
The route_name select is filled out with the follwing ajax code:
function showUser(str)
{
if (str=="")
{
document.getElementById("txtLocation").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()
{
var output = '';
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
output = xmlhttp.responseText;
document.getElementById("txtLocation").innerHTML=output;
}
}
xmlhttp.open("GET","../model/selected_loc.php?l="+str,true);
xmlhttp.send();
}
Which is called by this PHP code:
echo "<b><u>Location Information</u></b><br><br>";
echo "<select name='loc_id' id='loc_id' onchange='showUser(this.value)'><option value='0000'>... select a location ...</option>";
$result = mysql_query("SELECT loc_id, name FROM location ORDER BY name");
while ($row = mysql_fetch_array($result))
{
$id = $row['loc_id'];
$name = $row['name'];
echo "<option value='{$id}'>{$name}</option>";
}
echo "</select><br><br>";
There is also this javascript code acting on the form.
function switchRoute()
{
if (document.getElementById('route2').checked)
{
document.submitroute.route_name.disabled=true;
document.submitroute.new_route_name.disabled=false;
document.submitroute.route_grade.disabled=false;
document.submitroute.route_description.disabled=false;
}
else if (document.getElementById('route1').checked)
{
document.submitroute.route_name.disabled=false;
document.submitroute.new_route_name.disabled=true;
document.submitroute.route_grade.disabled=true;
document.submitroute.route_description.disabled=true;
}
}
Thanks for any assistance you can give me.
I feel rather silly, however I have solved it myself.
In the page which received the data I had:
Instead of:
This was reassigning the $route variable instead of comparing it. I swear I checked that earlier, however small things like that are sometimes easily missed.
Thanks to all those who helped or looked at my question.