希望有人可以帮助我。出于某种原因,以下表单代码始终将“路线”单选按钮的值设为“m”,即使选择了值为“s”的选项也是如此。
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>";
使用以下 ajax 代码填写 route_name 选择:
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();
}
由这个 PHP 代码调用:
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>";
还有这个 javascript 代码作用于表单。
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;
}
}
谢谢你能给我的任何帮助。