Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to use radio buttons in a function in javascript?

    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...

  • #2
    New Coder
    Join Date
    Jul 2010
    Posts
    61
    Thanks
    0
    Thanked 21 Times in 21 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    @phil thank you very much.
    anyone please tell me what possible changes i'll have to make for the code to be correct.

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    1. Use something other than "try" as the name for your form
    2. Look into using innerHTML to update the page contents, rather than document.write()


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •