SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question javascript if-then statement help needed

    i have a form that is using javascript to validate certain fields. at one point in the form is a radio button set that is used to designate that shipping and billing addresses are the same. i want the javascript to look for this and either continue validating or stop depending on what is checked (yes or no). here is the statement i inserted into the script:

    Code:
    if (document.forms[0].shipSame.value == "no")
        {//continue checking
        //error check code here
        }
    this doesn't seem to work. what is wrong with the statement?

  2. #2
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You forgot that the radio button is in an array
    PHP Code:
    function checkit()
    {

        if (
    document.forms[0].rad[1].value == "no")
        {
            
    document.forms[0];

            
    '';
            
    x+= 'rad[0] = radio option 1, which is equal to \'';
            
    x+= y.rad[0].value '\'\n';

            
    x+= 'rad[1] = radio option 2, which is equal to \'';
            
    x+= y.rad[1].value '\'\n\n';

            
    x+= 'this is how many radio options i have \''
            
    x+= y.rad.length '\'';

            
    alert(x);
        }


  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    site point messes up with escaping characters so

    change all the forward slashes to backslashes and it will work

    PHP Code:

    function checkit()
    {

        if (
    document.forms[0].rad[1].value == "no")
        {
            
    document.forms[0];

            
    '';
            
    x+= 'rad[0] = radio option 1, which is equal to /'';
            x+= y.rad[0].value + '
    /'/n';

            
    x+= 'rad[1] = radio option 2, which is equal to /'';
            x+= y.rad[1].value + '
    /'/n/n';

            
    x+= 'this is how many radio options i have /''
            x+= y.rad.length + '
    /'';

            
    alert(x);
        }


  4. #4
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how would it look if it was a checkbox instead? i really only need one button there and i only used radio because it looks better...

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what i beleive your trying to do is form validation right?

    well heres a little demo

    PHP Code:
    function checking_boxes()
    {

    document.forms[1];

        if (
    y.check[0].checked || y.check[1].checked//returns if either one is checked
        
    {

            
    '';
            
    x+= 'check[0] = checkbox/'s 1which the value is equal to /'';
            
    x+= y.check[0].value '/'/n';
            x+= '
    the check box was checked is ' + y.check[0].checked + '/n/n';

            x+= '
    check[1] = checkbox/'s 2, which the value is equal to /'';
            x+= y.check[1].value + '
    /'/n';
            
    x+= 'the check box was checked is = ' y.check[1].checked '/n/n/n';

            
    x+= 'this is how many checkbox/'s i have /''
            
    x+= y.check.length '/'';

            alert(x);

        }


  6. #6
    SitePoint Wizard bbolte's Avatar
    Join Date
    Nov 2001
    Location
    The Central Plains
    Posts
    3,304
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks alot andrew, appreciate it!


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
  •