Monday, May 5, 2008

Resetting the drop-downs (3 Drop - Downs)

Requirement:
We have 3 drop downs each containing the same values. If user selects one value (Search Criteria) in the first drop-down then he shouldn’t select the same in the next drop down. If the user selects the same value, then we need a throw a pop-up message saying this value is already selected and reset the drop down to default value.


<html:select size="1" property="advSearchCriteria1" name="RequestForm" styleClass="rmt-formTxt" style="margin-right:6px;" onchange="selectAdvSearchCriteria1();">
<html:option value="">Search Criteria1</html:option>
<logic:present name="RequestForm" property="searchDropList">
<bean:define id="row" name="RequestForm" property="searchDropList" />
<html:options collection="row" property="code" labelProperty="display" />
</logic:present>
</html:select>

function selectAdvSearchCriteria3()
{

var criteria1=document.forms[0].advSearchCriteria1.value;
var criteria2=document.forms[0].advSearchCriteria2.value;
var criteria3=document.forms[0].advSearchCriteria3.value;

if(criteria3 != '' && ((criteria3 == criteria1 ) (criteria3 == criteria2)))
{
alert("Already selected ");
document.forms[0].advSearchCriteria3.selectedIndex=0;
}
}

In the above function advSearchCriteria1 is a string property which will holds the selected search criteria by the user. Similarly we get the values of other drop-downs as well.

No comments: