Selection based validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • alexz

    Selection based validation

    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.
  • Erwin Moller

    #2
    Re: Selection based validation

    alexz wrote:
    [color=blue]
    > 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.[/color]

    Hi,

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

    Regards,
    Erwin Moller

    Comment

    • alexz

      #3
      Re: Selection based validation

      Erwin Moller <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in message news:<410fa6c5$ 0$49711$e4fe514 c@news.xs4all.n l>...[color=blue]
      > alexz wrote:
      >[color=green]
      > > 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.[/color]
      >
      > Hi,
      >
      > I would advise you to code that in Javascript.
      > :P
      >
      > Regards,
      > Erwin Moller[/color]
      Thank Erwin.
      You would have an example of that javascript script?

      Comment

      • Erwin Moller

        #4
        Re: Selection based validation

        alexz wrote:
        [color=blue]
        > Erwin Moller
        > <since_humans_r ead_this_I_am_s pammed_too_much @spamyourself.c om> wrote in
        > message news:<410fa6c5$ 0$49711$e4fe514 c@news.xs4all.n l>...[color=green]
        >> alexz wrote:
        >>[color=darkred]
        >> > 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.[/color]
        >>
        >> Hi,
        >>
        >> I would advise you to code that in Javascript.
        >> :P
        >>
        >> Regards,
        >> Erwin Moller[/color]
        > Thank Erwin.
        > You would have an example of that javascript script?[/color]

        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.myR adioButton[0].checked) {
        YesChecked=true ;
        if (theFormRef.fna me.value.length >0) {
        theFormRef.subm it();
        } else {
        alert ("You forgot to fill fname!");
        }
        }
        if (theFormRef.myR adioButton[1].checked) {
        NoChecked=true;
        if (theFormRef.lna me.value.length >0) {
        theFormRef.subm it();
        } else {
        alert ("You forgot to fill lname!");
        }
        }

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

        </script>


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

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

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

        Regards,
        Erwin Moller

        Comment

        Working...