SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    radio buttons + checked

    Hi all,

    I have in my page the following form:
    Code:
    <form action="this.php" method="get" name="newsform">
    <input type="radio" name="number" value="latest" checked="true" /> 5 latest news entries<br />
    <input type="radio" name="number" value="all" /> All news entries<br />
    <input type="radio" name="number" value="custom" /> Custom number: 
    <input type="text" name="custom" size="2" maxlength="2" class="white" onchange="newsformchange()" />
    <p><input type="submit" value="Submit" /></p>
    </form>
    and the javascript:
    Code:
    function newsformchange () {
      if ( document.newsform.custom.length < 1 )
        document.newsform.number['latest'].checked=true;
      if ( document.newsform.custom.length > 0 )
        document.newsform.number['custom'].checked=true;
    }
    but this code won't work! anyone an idea what the problem is

  2. #2
    SitePoint Zealot
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found the solution. you can't use onchange on a radio object, have to use onclick instead. also changed the JS to
    Code:
    function newsformchange () {
      document.newsform.number[0].checked = 0;
      document.newsform.number[2].checked = 1;
    }
    ow man I'm a JS-noob

  3. #3
    Must try harder! linmed01's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    250
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This works:

    Code:
    function newsformchange () {
      if ( document.newsform.custom.value.length <= 1 )
        document.newsform.number[0].checked=true;
      else
        document.newsform.number[2].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
  •