SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot fenryr's Avatar
    Join Date
    Oct 2005
    Location
    germany
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Checking Radiobttons

    Hi,

    I need to check a radiobutton after my page has loaded.

    This is what the HTML looks like:

    Code:
    <form action="questionnaire.php" method="post" id="t0">
    <input name="t0a1" id="t0a1" type="radio" value="1" />
    <input name="t0a1" id="t0a1" type="radio" value="2" />
    </form>
    What would the javascript look like?
    I know it's pretty simple but it won't work for some reason ..

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    you mean you want to have one of them initially selected?

    <input name="t0a1" id="t0a1" type="radio" value="1" checked="checked" />

    but if you want to do it via javascript, this probably would workw:

    window.onload = function() {
    document.getElementById('t0al').checked = true;
    }

  3. #3
    SitePoint Zealot fenryr's Avatar
    Join Date
    Oct 2005
    Location
    germany
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Woaahh.. solved it myself .. I needed to add the name attribute to the form.. I can't access it via the id it seems..

  4. #4
    SitePoint Zealot fenryr's Avatar
    Join Date
    Oct 2005
    Location
    germany
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks anyway Raffles..

    I used this code to check the radio:

    var xx = document.t0.t0a1[0];
    xx.checked = true


Bookmarks

Posting Permissions

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