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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2003
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with javascript and form fields

    Hello,

    I am still developing my javascript skills and have a question.

    Say I have two radio buttons with the same name but different value. Selecting one of the radios is required. There are two text fields and depending on which radio is selected, one of the two text fields would be required.

    So I have radios named "type" one value is "current" and one is "new".

    If new is selected, then the text field "pbname" is requireed. If new is selected then the text field "reqno" is required.

    I have spent about 5 hours scouring the net for examples, so if there is somewhere I can look, please help.

    Thanks!

    Jim

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    626
    Thanks
    0
    Thanked 0 Times in 0 Posts
    With radio buttons that have the same name the browser would set them up in an array so you could determine if one or the other has been "checked" like this:
    if(document.form_name.type[0].checked)
    {do something}
    else
    {do something}

    This would determine if the first radio button has been checked and if it has perform the statements within the first set of curly brackets. If not then do the statements in the next set of brackets (else). Hope that helps.


  •  

    Posting Permissions

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