SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Radio buttons

  1. #1
    SitePoint Zealot XandroZ's Avatar
    Join Date
    May 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Radio buttons

    I have a web page that change the value inserted in a textfield when you set a radio button(this is a Group of Radio Buttons).The textfield is readonly.The problem is if I click in the textfield it change the value and the radio selection, but the textfield is readonly.I can use disable because some time the length value(text) is biger then textfield size.

    Un example:
    Java script code :

    Code:
    function test(){
    var i;
    var form = document.forms[0];
    for ( i = 0; i < form.RadioGroup1.length; i++) {
    if (form.RadioGroup1[i].checked) {
    break;
    }
    }
    if (i==0) {
    
    document.getElementById("terr").value=0.5632423; 
    } 
    else 
    if (i==1){ 
    
    document.getElementById("terr").value=9.3;
    }
    }
    </script>
    and the HTML form code
    Code:
    <div id="ltest">
      <input style="width:20px" name="textfield" type="text" id="terr" maxlength="17" readonly>
    </div>
    <div id="Layer24">
    <form action="" method="post" id="form1">
      <table width="200">
        <tr>
          <td><label>
            <input name="RadioGroup1" type="radio" onChange="test()"  >
            mas</label></td>
        </tr>
        <tr>
          <td><label>
            <input name="RadioGroup1" type="radio" onChange="test()" >
            atom</label></td>
        </tr>
      </table>
    </form>

  2. #2
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    simply change onChange to onClick.

    It is because onChange fires when it is de-selected also,

    -ALL
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site

  3. #3
    SitePoint Zealot XandroZ's Avatar
    Join Date
    May 2006
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thx
    I will check www.wsforums.com and I will tell about it to my friends

  4. #4
    SitePoint Addict ALL's Avatar
    Join Date
    Oct 2005
    Location
    South Dakota
    Posts
    215
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    thanks
    Did I help you?
    You can repay me, support one of my projects (no money needed):
    JavaScript Wiki, Another Web Forum, Paranormal Site


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
  •