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 12 of 12
  1. #1
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkbox checked check another checkbox

    yes I know seems a joke of words but i need exactly this:

    2 checkbox where the second one follow the action of the first one.

    thanks in advance

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <form>
    <input type="checkbox" name="checkers" id="checker1" onclick="this.form.checker2.checked = this.checked;" />
    <input type="checkbox" name="checkers" id="checker2" />
    </form>
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Does the first one follow the action of the second as well? If so, add a set_c1() function that is just the opposite.

    <html>
    <head>
    <script language="javascript">
    function set_c2(x){
    if (x.checked)
    document.myform.c2.checked=true;
    else
    document.myform.c2.checked=false;
    }
    </script>
    </head>
    <body>
    <form name="myform">
    <input type="checkbox" name="c1" value="on" onclick="set_c2(this)"><input type="checkbox" name="c2" value="on">
    </form>
    </body>

    </html>

  • #4
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes that's work fine but i need something like this and so I need that you can choose only one of otpion (male-female).
    please take a look at code

    <script language="javascript">
    function set_c2(x){
    if (x.checked)
    document.myform.c2.checked=true;
    else
    document.myform.c2.checked=false;
    }
    function set_c3(x){
    if (x.checked)
    document.myform.c3.checked=true;
    else
    document.myform.c3.checked=false;
    }
    </script>
    </head>
    <body>
    <form name="myform">
    <p> male
    <input type="radio" name="male" value="male" onclick="set_c2(this)">
    female
    <input type="radio" name="female" value="female" onClick="set_c3(this)">
    </p>
    <p>
    <input type="checkbox" name="c2" value="on">
    maleicon
    <input type="checkbox" name="c3" value="on" onClick="set_c3(this)">
    femaleicon</p>
    </form>

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Ok, you are using radio buttons, not checkboxes. They are designed to support exactly what you want to do without using any javascript. Just give them both the same name.

    <input type="radio" name="sx" value="male">I am male<br>
    <input type="radio" name="sx" value="female">I am female
    Last edited by arnyinc; 01-08-2003 at 08:18 PM.

  • #6
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok,
    I'm sorry to change but I'm working on it now
    I've sorted best thing to do what I need is this:

    <form name="myform">
    <p> male
    <input type="radio" name="sex" value="male" >
    female
    <input type="radio" name="sex" value="female" >
    </p>
    <p>
    <input type="hidden" name="hiddenField" value="maleicon.gif">
    maleicon </p>
    </form>

    where the hidden field take value from the selected radio button.
    not exactly the same value but if male=maleicon.gif if female=femaleicon.gif
    if you can solve that you are a GReat and apologize for changes..

  • #7
    Senior Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    1,137
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you just add an onclick something like
    onClick="documnet.myform.hiddenfiled.value=femaleicon.gif"
    to the female one and just have the defualt value for hiddenfiled as maleicon.gif

    scroots
    Spammers next time you spam me consider the implications:
    (1) that you will be persuaded by me(in a legitimate mannor)
    (2)It is worthless to you, when i have finished

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Just to put it in code:


    <form name="myform">
    <p> male
    <input type="radio" name="sex" value="male" onClick="document.myform.hiddenField.value='maleicon.gif'" checked>
    female
    <input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'">
    </p>
    <p>
    <input type="hidden" name="hiddenField" value="maleicon.gif">
    </p>
    </form>

  • #9
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what intial value for the hiddenfield?
    cause it remains ever maleicon.gif

    thanx a lot for help

  • #10
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    sorry it works fine!!!!

    thanks again and good coding...

  • #11
    New Coder
    Join Date
    Jan 2003
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how can set at the same time 2 hiddenfields???

    <input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'"; ="document.myform.hiddenField2.value='femaleicon2.gif'"; >

    will this work??
    thank

  • #12
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by scsi
    <input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'"; ="document.myform.hiddenField2.value='femaleicon2.gif'"; >
    change it to
    Code:
    <input type="radio" name="sex" value="female" onClick="document.myform.hiddenField.value='femaleicon.gif'; document.myform.hiddenField2.value='femaleicon2.gif'>


  •  

    Posting Permissions

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