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

    [help] adding validation form combo

    help, i have form with multiple combobox, i want add validation for submition selected combobox, this my form.. http://pastebin.com/k8r5Rnw4 at form have tabel SPh, CYL, Axis, i want to add validation for tabel SPH, CYL, AXIS, for this role..

    SPH- CYL-AXIS
    None - None - None... allow submit form
    value - value - value ... allow submit
    value - none - none ... allow submit
    value - value - none ... cannot submit

    please.. help me, thanks regards...

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Firstly, not to split hairs, but you don't have multiple comboboxes; if you are using the combobox library, you have multiple SELECT tags that use the combobox library - if you don't use the combobox library, you just have multiple SELECT tags (sometimes aka "drop-downs").

    Assuming that the labels are the IDs (not name) of the SELECT tags (and you didn't give the FORM id, so I'm giving it an arbitrary id)..

    Code:
    function validateForm(){
      var formObj = document.forms["thisForm"];
      if((formObj.SPh.selectedIndex > 0) && 
        (formObj.CYL.selectedIndex > 0) &&
        (formObj.Axis.selectedIndex == 0)){
          alert("Form cannot submit like this"); return false;
          }
    }
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #3
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    id combo is a, aa, aaa,aaaa,.... see my form at http://pastebin.com/k8r5Rnw4 my validation by value="0" but I want to add another validation for combo a ,aa,aaa,aaa.. the validation is cannot submit form before selecting first combo.... please help...

  • #4
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
      function validasi() {
          if(
    document.getElementById("xxx2").checked) {
            
    alert("Maaf, untuk pemesanan product dengan ukuran Anda silahkan menghubungi customer support  via live chat, SMS, atau BBM ");
            return 
    false//batalkan submit, radio ke-2 yg di pilih
          
    }
         
          if(
    document.getElementById("a").value=="0") {
            
    alert("Maaf, untuk pemesanan product dengan ukuran Anda silahkan menghubungi customer support  via live chat, SMS, atau BBM ");
            return 
    false//batalkan submit, opsi 'a' belum dipilih
          
    }
         
          if(
    document.getElementById("aa").value=="0") {
            
    alert("Maaf, untuk pemesanan product dengan ukuran Anda silahkan menghubungi customer support  via live chat, SMS, atau BBM");
            return 
    false//batalkan submit, opsi 'aa' belum dipilih
          
    }
         
          if(
    document.getElementById("aaa").value=="0") {
            
    alert("Maaf, untuk pemesanan product dengan ukuran Anda silahkan menghubungi customer support  via live chat, SMS, atau BBM");
            return 
    false//batalkan submit, opsi 'aaa' belum dipilih
          
    }
               if(
    document.getElementById("aaaa").value=="0") {
            
    alert("Maaf salah");
            return 
    false//batalkan submit, opsi 'aaa' belum dipilih
          
    }
           
            if(
    document.getElementById("aaaaa").value=="0") {
            
    alert("Maaf, untuk pemesanan product dengan ukuran Anda silahkan menghubungi customer support via live chat, SMS, atau BBM ");
            return 
    false//batalkan submit, opsi 'aaa' belum dipilih
          

    how to add validation, if "a" is selected then have to selected "aa" if "aa" selected then have to selected "aaa"... -> not allow select next dropdown before selected first dropdown..
    Last edited by vespaman; 02-21-2013 at 08:51 AM.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    Have a look at http://www.codingforums.com/showthread.php?t=272864

    and

    http://www.codingforums.com/showthread.php?t=169465

    As your post is partly in a foreign language, I am not sure that I completely understand what you want, but if you have three select lists you can obtain the selected indices of all three with:-

    Code:
    var val1 = document.getElementById("a").selectedIndex;
    var val2 = document.getElementById("aa").selectedIndex;
    var val3 = document.getElementById("aaa").selectedIndex;
    and then use if..else statements to identify combinations where submission is not allowed:-

    Code:
    if (val1 > 0) && (val2 > 0) && (val 3 == 0)) {
    return false; // cannot submit.
    }
    This is in effect what WolfShade has suggested.

    I assume (or hope!) that your select lists do not really have the ids a,aa,aaa, aaaa etc. If they do, that is horrible!


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 02-21-2013 at 09:27 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    New to the CF scene
    Join Date
    Feb 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    not multiple combo just multiple SELECT tags /dropdownlist , validation is not allow select next dropdown before selected first dropdown..

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,556 Times in 2,534 Posts
    Quote Originally Posted by vespaman View Post
    not multiple combo just multiple SELECT tags /dropdownlist , validation is not allow select next dropdown before selected first dropdown..
    Have you looked at the links to the forum threads which I gave you?

    Or here is another example:-

    Code:
    <select id = "fruits" onchange = "go()">
    <option selected value=""> Choose A Fruit</option>
    <option value='Mango'> Mango </option>
    <option value='Apple'> Apple </option>
    <option value='Orange'> Orange </option>
    </select>
    
    <select id = "colours" onchange = "go()">
    <option selected value=""> Choose A Colour</option>
    <option value='Red'> Red </option>
    <option value='Green'> Green</option>
    <option value='Blue'> Blue </option>
    </select>
    
    <select id = "size" onchange = "go()">
    <option selected value=""> Choose A Size</option>
    <option value='Large'> Large </option>
    <option value='Medium'> Medium</option>
    <option value='Small'> Small </option>
    </select>
    
    
    <script type = "text/javascript">
    
    function go() {
    
    var val1 = document.getElementById("fruits").value
    var val2 = document.getElementById("colours").value
    var val3 = document.getElementById("size").value
    
    if (val1 == "") {
    document.getElementById("colours").selectedIndex = 0;
    document.getElementById("size").selectedIndex = 0;
    alert ("You must select a fruit, then a colour, then a size");
    return false;
    }
    
    if ((val3 != "") && (val2 == "")) {
    document.getElementById("size").selectedIndex = 0;
    alert ("You must choose a colour before selecting a size");
    return false;
    }
    
    if (val3 == "") {return false}
    
    alert ("You have selected:-   " + val1 + "   " + val2 + "   " + val3);
    
    }
    
    </script>
    Last edited by Philip M; 02-21-2013 at 10:10 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

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