...

View Full Version : how to use radio buttons in a function in javascript?



neerja
07-20-2010, 12:30 PM
hi,
i tried to run the following code with IE but it gives error as
" document.try.radiogrp is null or not a object."

<code>
<html>
<head>
<script language="javascript">
function fresh()
{ document.write("question 1's options are")
document.write("option 1:"+document.try.radiogrp[0].value+"<br/>")
document.write("option 2:"+document.try.radiogrp[1].value+"<br/>")
document.write("option 3:"+document.try.radiogrp[2].value+"<br/>")
}
</script>

</head>
<body>
<form name="try" >
<input type="radio" name="radiogrp" id="r1" value="yes">yes
<input type="radio" name="radiogrp" id="r2" value="no">no
<input type="radio" name="radiogrp" id="r3" value="may be">may be
<input type="button" value="begin" onClick="fresh();">
</form>
</body>
</html>
</code>
please help me find the error and run it correctly with IE.
thanx...

RandomUser531
07-20-2010, 12:39 PM
document.write can only be called during the initial building of a document, not after it is loaded.
Also try is a reserved word and should not be used as an identifier.

neerja
07-20-2010, 12:46 PM
@phil thank you very much.
anyone please tell me what possible changes i'll have to make for the code to be correct.

Spudhead
07-20-2010, 01:02 PM
1. Use something other than "try" as the name for your form
2. Look into using innerHTML (http://www.tizag.com/javascriptT/javascript-innerHTML.php) to update the page contents, rather than document.write()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum