Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
Javascript help. Form validation.
  • Posted: 30.05.2005, 04:45
     
    silverscout
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    18.06.08
    Posts:
    408

    Code

    if(document.vwarform.contactircchannel.value == "")
        {
            alert("Read COC is blank. You must type YES!");
            document.vwarform.contactircchannel.focus();
            return false;
        }
        if(document.vwarform.contactircchannel.value == "YES")
        {
            alert("Read COC is other than yes. You must type YES!");
            document.vwarform.contactircchannel.focus();
            return false;
        }


    The First statement works. However, the second is skipped. Anyone know
    why?
    I want that field to be YES and not blank or any other text.
  • Posted: 30.05.2005, 16:25
     
    Lobos
    rank:
    Professional Professional
    registered:
     December 2002
    Status:
    offline
    last visit:
    24.08.08
    Posts:
    1588
    Try this

    Code

    if(document.vwarform.contactircchannel.value == "")
        {
            alert("Read COC is blank. You must type YES!");
            document.vwarform.contactircchannel.focus();
            return false;
        }
        else if(document.vwarform.contactircchannel.value != "YES")
        {
            alert("Read COC is other than yes. You must type YES!");
            document.vwarform.contactircchannel.focus();
            return false;
        }


    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Posted: 30.05.2005, 18:15
     
    silverscout
    rank:
    Helper Helper
    registered:
     November 2004
    Status:
    offline
    last visit:
    18.06.08
    Posts:
    408
    that works. However not for yes (lowercase)
    I have tried

    else if(document.vwarform.contactircchannel.value != "YES" || "yes")

    and

    else if(document.vwarform.contactircchannel.value != "YES" || document.vwarform.contactircchannel.value != "yes")

    and

    else if(document.vwarform.contactircchannel.value != "YES") || (document.vwarform.contactircchannel.value != "yes")

    also tried it with the ^ operator in all 3 ways.
  • Posted: 30.05.2005, 19:11
     
    craigh
    rank:
    Professional Professional
    registered:
     June 2003
    Status:
    offline
    last visit:
    27.08.08
    Posts:
    1147
    you may wish to try the toUpperCase method to solve that
  • Posted: 30.05.2005, 20:50
     
    Lobos
    rank:
    Professional Professional
    registered:
     December 2002
    Status:
    offline
    last visit:
    24.08.08
    Posts:
    1588
    Well you are obviously wanting a yes answer so why not use a check box - this will acheive the same thing without all the mucking around...

    -Lobos

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula