Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

compare values of dynamic dropdown-lists

Status
Not open for further replies.

bogan

Programmer
Aug 27, 2003
6
CH
Hi experts!

I need help for the following problem:

I have a form with several "rows" of dynamically created dropdown-boxes:

<form name=&quot;form&quot; action=&quot;something.php&quot; method=&quot;post&quot; onSubmit=&quot;return chkFormular();&quot;>

<select name=&quot;1-HANS-1&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;1-FRIT-1&quot; size=&quot;1&quot;> ... [with option fields]
...
<select name=&quot;1-HANS-2&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;1-FRIT-2&quot; size=&quot;1&quot;> ... [with option fields]
...
<select name=&quot;1-HANS-3&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;1-FRIT-3&quot; size=&quot;1&quot;> ... [with option fields]
...
...
<select name=&quot;2-HANS-1&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;2-FRIT-1&quot; size=&quot;1&quot;> ... [with option fields]
...
<select name=&quot;2-HANS-2&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;2-FRIT-2&quot; size=&quot;1&quot;> ... [with option fields]
...
<select name=&quot;2-HANS-3&quot; size=&quot;1&quot;> ... [with option fields]
<select name=&quot;2-FRIT-3&quot; size=&quot;1&quot;> ... [with option fields]
...

so thats somehow two loops nested, one creates the first letter of the name and within this loop another loop that creates the second letter behind the name.

everything is dynamically created depending on the data in the database.

I need to check:
if the field &quot;1-HANS-1&quot; has option selceted with value > &quot;0&quot; then the filed &quot;1-FRIT-1&quot; MUST have selected a value bigger than &quot;0&quot;.
[for both dropdown-fields the values are &quot;0&quot;, &quot;10&quot;, &quot;20&quot;, ..., &quot;100&quot;]
and in same manner I need to compare &quot;1-HANS-2&quot; with &quot;1-FRIT-2&quot; and so on, until the inner loop is finished. And the same procedure for the &quot;outer loop&quot;: &quot;2-HANS-1&quot; compared with &quot;2-FRIT-2&quot;, then &quot;2-HANS-2&quot; with &quot;2-FRIT-2&quot; and so on.

can anyone help me?
 
<script>
function checkSelects(){
//I'm not sure on this next line - it may be &quot;select&quot; instead
allSelects = document.getElementsByTagName(&quot;select - one&quot;)
for (x=0; x<allSelects.length; x++){
if (allSelects[x].name.indexOf(&quot;HANS&quot;) > 1 && allSelects[x].selectedIndex > 0){
if (allSelects[x+1].selectedIndex == 0){
alert(allSelects[x+1] + &quot; needs a selection&quot;)
}
}
}
}
</script>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook
 
hi mwolf00

thanx a lot for your script!
i had to change the &quot;select - one&quot; to &quot;select&quot; and the fieldname in the alert needs the &quot;.name&quot;, but now it works. thanx a lot, you really did help!

<script>
function checkSelects(){
allSelects = document.getElementsByTagName(&quot;select&quot;);
for (x=0; x<allSelects.length; x++){
if (allSelects[x].name.indexOf(&quot;HANS&quot;) > 1 && allSelects[x].selectedIndex > 0){
if (allSelects[x+1].selectedIndex == 0){
alert(allSelects[x+1].name + &quot; needs a selection&quot;);
allSelects[x+1].focus();
return false;
}
}
}
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top