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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count number of times a drop down box has been selected

Status
Not open for further replies.

rkoya

IS-IT--Management
Joined
Jul 12, 2004
Messages
57
Location
GB
Hello,

I was wondering if anyone could help. I have the following form:

<tr>
<td colspan="2"> <select name="classes" id="classes" class="box3" >
<option value="NONE" selected>Class</option>
<option value="M">Mini</option>
<option value="E">Economy</option>
<option value="C">Compact</option>
<option value="I">Intermediate</option>
<option value="S">Standard</option>
<option value="F">Full Size</option>
<option value="P">Premium</option>
<option value="L">Luxury</option>
<option value="X">Special</option>
</select> </td>
</tr>
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<td colspan="2"> <select name="type" id="type" class="box3">
<option value="NONE" selected>Type</option>
<option value="B">2 door</option>
<option value="D">4 door</option>
<option value="W">Wagon</option>
<option value="V">Van</option>
<option value="S">Sport</option>
<option value="T">Convertible</option>
</select> </td>
</tr>
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<td colspan="2"> <select name="transmission" id="transmission" class="box3">
<option value="NONE" selected>Transmission</option>
<option value="A">Auto</option>
<option value="M">Manual</option>
</select> </td>
</tr>
<tr>
<td height="5" colspan="2"></td>
</tr>
<tr>
<td colspan="2"> <select name="ac" id="ac" class="box3">
<option value="NONE" selected>A/C</option>
<option value="N">No air conditioning</option>
<option value="R">Air conditioning </option>
</select> </td>
</tr>

Basically at present when selecting an option it calls a function depending on what is selected to remove unwanted products. Example of javascript code:

function greyout1(){

var sipps = document.getElementsByTagName("div");
var classes;
classes = document.form2.classes.value;

if (classes=='NONE'){
greyout2();
}
else{

for (var i=0; i < sipps.length; i++){
var currentsipp = sipps.getAttribute("id");


if (sipps.className!='trans25'){


if ( (currentsipp.charAt(0)=='*') && ( (classes) == (currentsipp.charAt(1)) ) ) {

sipps.className='transOFF';
}
else if ( (currentsipp.charAt(0)=='*') && ( (classes) != (currentsipp.charAt(1)) ) ) {
sipps.className='trans25';}


}
}
}
}

However, the drop down box can only be selected once, if the same one is chosen again then it removes everything. I need a process to basically count how many times a specific the drop down box has been selected and if it is more than 1 then reset the display and remember the selection in the drop down box.

I hope this makes sense.

Thanks
 
I am not entirely clear on what you are trying to do.
Your code above does not show any calls to the javascript functions either. I would have assumed an onchange or onclick event.

One way is to set each select box to a default value such as "Select One" and in your javascript function you check the selected value of that field and if it IS at the default then you allow the change, otherwise deny it.



Stamp out, eliminate and abolish redundancy!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top