cancel
Showing results for 
Search instead for 
Did you mean: 

Prompting the user to make a selection in the Dropdownlist box

Former Member
0 Kudos

Hi, I have created a DropdownList box using the following code:

<tr>

<td>

<hbj:dropdownListBox

id="ORGANIZATION"

selection=" ">

<hbj:listBoxItem key=" " value=" " />

<hbj:listBoxItem key="Marketing" value="Marketing" />

<hbj:listBoxItem key="Finance" value="Finance" />

<hbj:listBoxItem key="IT" value="IT" />

</hbj:dropdownListBox>

</td>

</tr>

By default, the selection in the Dropdownlist box is blank. The user will select one of the 3 departments mentioned above. However, if the user does not select any of the 3 departments, he should be prompted to do so. This should happen before the user clicks on the "Send" button which emails the form. Can anyone please help me? Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

MartyMcCormick
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Sri,

You can add an onClientClick to your send button and evaluate the value in the drop down box. Something like the following should work.


function CheckForm() {    
var funcName = htmlb_formid+"_getHtmlbElementId";
func = window[funcName];     
var dropDownValue = eval(func("ORGANIZATION"));    
if (dropDownValue.getValue() == " ") {    	
alert("You must select from the drop down box!");
htmlbevent.cancelSubmit=true;    	
return false;    }   
else   {	return true;	   }
}

then your drop down like such:


<tr>
<td>
<hbj:dropdownListBox
id="ORGANIZATION"
selection=" "
jsObjectNeeded="true">
<hbj:listBoxItem key=" " value=" " />
<hbj:listBoxItem key="Marketing" value="Marketing" />
<hbj:listBoxItem key="Finance" value="Finance" />
<hbj:listBoxItem key="IT" value="IT" /> 
</hbj:dropdownListBox>
</td>
</tr>

To recap, your javaScript function should return false if the user has not selected a value. Also, please remember to add the parameter jsObjectNeeded="true" to your ORGANIZATION dropdown list so you can reference it from javaScript. Your button should have an onClientClick="CheckForm" as well.

Hope this helps.

Marty

FYI: Also discussed here:

https://www.sdn.sap.com/sdn/collaboration.sdn?contenttype=url&content=https%3A//forums.sdn.sap.com/t...

Former Member
0 Kudos

Hi Marty, thank you so much. Your code is excellent. I followed all the steps you had outlined and used your code. I was immediately able to get it working. Once again, thanks a lot for the great help.

Sincerely,

Sri

Answers (0)