Issue
UPDATE: Sorry, when removing syntax from perl script I removed a little too much. Here's the code thus far. I am posting "student_name" to script.pl. This can either be entered in a text form or selected from the drop down box based on which you choose using a radio button. But it doesn't seem to work for me.
<form method="post" action="script.pl">
Type Student Name<input type="radio" name="student_name"><input type=text name="student_name" size=50>
<b>OR</b>
Select Student Name<input type="radio" name="student_name">
<select name="student_name">
<option value="jack">Jack</option>
</select>
</form>
OLD POST---------------------------------------------------------------------------------------------------------------- I am trying to create a form where either a user can check the first radio button and enter a name himself or check the second button and select a value from the drop down list and pass it over. For some reason I can't get it to work properly, the value does not pass. I want whatever value is entered or selected after the radio button to be posted.
Enter Name () _______ OR () (drop down box)
<td width=30% bgcolor=#CEDBE7>Student Name</td>
<td bgcolor=#CEDBE7 width=70%>
<input type=radio name=student_name value=><input type=text name=student_name size=50>
<b>OR</b>
<input type=radio name=student_name>
<select>
<option value=drop1>drop down option 1</option>
</select>
Solution
I THINK you mean this
window.onload=function() { // when the page has loaded
var rads = document.querySelectorAll('input[name="student_rad"]'); // get all radios with name student_rad
for (var i=0;i<rads.length;i++) {
rads[i].onclick=function() { // assign onclick to each
if (this.id=="inp") { // the one deciding input
document.getElementById("stud_sel").selectedIndex=0; // reset select
document.getElementById("student_name").focus();
}
}
}
document.getElementById("stud_sel").onchange=function() { // when selecting
document.getElementById("sel").click(); // click the rad to select it
document.getElementById("student_name").value=this.value;
}
var rad = document.querySelector('input[name="student_rad"][checked]');
if (rad == null) {
document.getElementById("inp").click(); // check default
}
}
<td width=30% bgcolor=#CEDBE7>Student Name</td>
<td bgcolor=#CEDBE7 width=70%>
<input type="radio" name="student_rad" id="inp"/><input type="text" name="student_name" id="student_name" size=50 />
<b>OR</b>
<input type="radio" name="student_rad" id="sel" />
<select id="stud_sel">
<option value="">Please select</option>
<option value="Frank">Frank</option>
</select>
Answered By - mplungjan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.