<HTML>
<HEAD>
<?
?>
<SCRIPT Language = "JavaScript">
function showChoice() {
var msg = ""
if (document.ReaderInfo.gender[0].checked) {
msg = document.ReaderInfo.gender[0].value
msg2 = document.ReaderInfo.gender[0].value
}
if (document.ReaderInfo.gender[1].checked) {
msg = document.ReaderInfo.gender[1].value
}
alert ("You chose "+msg)
}
</SCRIPT>
</HEAD>
<BODY>
<FORM name = "ReaderInfo">
<p>
<input name="textfield" type="text" size="1" maxlength="1" value="<? echo $test; ?>">
</p>
<p>
<INPUT TYPE="RADIO" NAME="gender" VALUE="America" onClick="showChoice()">
America<BR>
<INPUT TYPE="RADIO" NAME="gender" VALUE="Chinese" onClick="showChoice()">
Chinese<BR>
</p>
<P>
<INPUT type="button" value="Click Me" onClick="showChoice()">
</FORM>
</BODY>
</HTML>
Above is my current coding and its works. My only question is if my radio button and its value all generated from the database, how can I define the value in the javascript.
Currently I have america and chinese in gender radio button. what if I have japanese, french, german to add into radio button.
Any simple javascript to loop rather than define the gender[value] inside? IF i have 100 value, then I have to write 100 if statement in
javascript. Any idea to shorten the script in javascript?
Thanks.