Selection based validation

Discussion in 'Javascript' started by alexz, Aug 3, 2004.

  1. alexz

    alexz Guest

    I want to check information is entered in the form with javascrip,
    based on a radio button or a checkbox. For example I have 2 radio
    buttons Yes and No. If "Yes" is click then check if the fname field is
    filled. If "No" is checked, check if the lname was filled. Of course i
    also need a vlidation for the status (yes or no) it self.
    Thank.
    alexz, Aug 3, 2004
    #1
    1. Advertising

  2. alexz

    Erwin Moller Guest

    alexz wrote:

    > I want to check information is entered in the form with javascrip,
    > based on a radio button or a checkbox. For example I have 2 radio
    > buttons Yes and No. If "Yes" is click then check if the fname field is
    > filled. If "No" is checked, check if the lname was filled. Of course i
    > also need a vlidation for the status (yes or no) it self.
    > Thank.


    Hi,

    I would advise you to code that in Javascript.
    :p

    Regards,
    Erwin Moller
    Erwin Moller, Aug 3, 2004
    #2
    1. Advertising

  3. alexz

    alexz Guest

    Erwin Moller <> wrote in message news:<410fa6c5$0$49711$4all.nl>...
    > alexz wrote:
    >
    > > I want to check information is entered in the form with javascrip,
    > > based on a radio button or a checkbox. For example I have 2 radio
    > > buttons Yes and No. If "Yes" is click then check if the fname field is
    > > filled. If "No" is checked, check if the lname was filled. Of course i
    > > also need a vlidation for the status (yes or no) it self.
    > > Thank.

    >
    > Hi,
    >
    > I would advise you to code that in Javascript.
    > :p
    >
    > Regards,
    > Erwin Moller

    Thank Erwin.
    You would have an example of that javascript script?
    alexz, Aug 3, 2004
    #3
  4. alexz

    Erwin Moller Guest

    alexz wrote:

    > Erwin Moller
    > <> wrote in
    > message news:<410fa6c5$0$49711$4all.nl>...
    >> alexz wrote:
    >>
    >> > I want to check information is entered in the form with javascrip,
    >> > based on a radio button or a checkbox. For example I have 2 radio
    >> > buttons Yes and No. If "Yes" is click then check if the fname field is
    >> > filled. If "No" is checked, check if the lname was filled. Of course i
    >> > also need a vlidation for the status (yes or no) it self.
    >> > Thank.

    >>
    >> Hi,
    >>
    >> I would advise you to code that in Javascript.
    >> :p
    >>
    >> Regards,
    >> Erwin Moller

    > Thank Erwin.
    > You would have an example of that javascript script?


    Hi Alex,

    I was being just a little ironical.
    I did that because I thought your question was very vague.
    Being ironical is not nice, so I'll make it up to you.
    :)

    Two things:
    1) Why I think your question is bad.
    2) the solution to your problem (assuming I understood well).

    1) Why is your question bad?
    Because it was not clear what it is you cannot do.
    Do you expect this newsgroup to give you some examplecode? Or is there some
    particular thing you do not understand?

    What is it that you cannot do?
    Or what is it that doesn't work?
    Do you not know how to get the state of a radiobuttun?
    Do you not know how to use an if/else statement?

    2) solution.
    Because I am in a lot better mood than yesterday, here is the code to check
    what you want. :)
    I wrote is quit elaborately, to make clear how things work (I hope).

    -------------------------------------

    <html>
    <body>

    <script type="text/javascript">
    function checkIt(){
    var YesChecked = false;
    var NoChecked = false;

    var theFormRef = document.forms.myForm;

    if (theFormRef.myRadioButton[0].checked) {
    YesChecked=true;
    if (theFormRef.fname.value.length>0) {
    theFormRef.submit();
    } else {
    alert ("You forgot to fill fname!");
    }
    }
    if (theFormRef.myRadioButton[1].checked) {
    NoChecked=true;
    if (theFormRef.lname.value.length>0) {
    theFormRef.submit();
    } else {
    alert ("You forgot to fill lname!");
    }
    }

    // checked anything?
    if ((!YesChecked) && (!NoChecked)){
    alert ("please check yes or no!");
    }
    }

    </script>


    <form name="myForm" action="somescript.php" Method="post">
    <input type="radio" name="myRadioButton" value="Y"> Yes
    <br>
    <input type="radio" name="myRadioButton" value="N"> No
    <br>
    fname: <input type="text" name="fname">
    <br>
    lname: <input type="text" name="lname">

    <input type="button" onClick="checkIt()" value="click me">
    </form>
    </body>
    </html>

    -------------------------------------

    Regards,
    Erwin Moller
    Erwin Moller, Aug 6, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Simon Niederberger
    Replies:
    2
    Views:
    16,452
    Christian Kaufhold
    Jan 7, 2005
  2. Andrew Crowe
    Replies:
    1
    Views:
    4,446
    Andrew Crowe
    Sep 13, 2004
  3. Gary W. Smith

    Validation based on radio button selection

    Gary W. Smith, Jul 30, 2007, in forum: ASP .Net
    Replies:
    2
    Views:
    6,424
    Gary W. Smith
    Aug 3, 2007
  4. curiousity

    HOWTO autopost the selection list upon selection

    curiousity, Nov 21, 2003, in forum: ASP .Net Mobile
    Replies:
    0
    Views:
    260
    curiousity
    Nov 21, 2003
  5. Loebb
    Replies:
    0
    Views:
    193
    Loebb
    Feb 23, 2004
Loading...

Share This Page