Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-20-2013, 02:53 PM   PM User | #1
vespaman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
vespaman is an unknown quantity at this point
[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...
vespaman is offline   Reply With Quote
Old 02-20-2013, 04:14 PM   PM User | #2
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 950
Thanks: 7
Thanked 98 Times in 98 Posts
WolfShade is an unknown quantity at this point
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".
WolfShade is offline   Reply With Quote
Old 02-21-2013, 07:21 AM   PM User | #3
vespaman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
vespaman is an unknown quantity at this point
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...
vespaman is offline   Reply With Quote
Old 02-21-2013, 07:41 AM   PM User | #4
vespaman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
vespaman is an unknown quantity at this point
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 07:51 AM..
vespaman is offline   Reply With Quote
Old 02-21-2013, 08:03 AM   PM User | #5
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 02-21-2013 at 08:27 AM..
Philip M is offline   Reply With Quote
Old 02-21-2013, 08:24 AM   PM User | #6
vespaman
New to the CF scene

 
Join Date: Feb 2013
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
vespaman is an unknown quantity at this point
not multiple combo just multiple SELECT tags /dropdownlist , validation is not allow select next dropdown before selected first dropdown..
vespaman is offline   Reply With Quote
Old 02-21-2013, 08:28 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,037
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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>
__________________

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.

Last edited by Philip M; 02-21-2013 at 09:10 AM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
form, javascript, validation

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:09 AM.


Advertisement
Log in to turn off these ads.