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!

cfselect and required

Status
Not open for further replies.

gtbikerider

Technical User
Joined
May 22, 2001
Messages
81
Location
GB
I am trying to force a selection be made from a dropdown list. Using "cfselect" and setting required to "yes" would appear to prevent selection of the "selected" option, but it doesn't work. Any idea what I am missing, or is this a bug that has to be worked around with javascript?


<cfselect name=&quot;myname&quot; required=&quot;Yes&quot; message=&quot;you must select something&quot;>
<option value=&quot;null&quot; selected>Please Select</option>
<option value=&quot;1&quot;>option 1</option>
<option value=&quot;2&quot;>option 2</option>


--
John Carratt
 
I don't use the cfform stuff, but can you have &quot;null&quot; as the value of the Select option, which would pass a string of &quot;null&quot; Try putting no value in there and see if that fixes it:

<option value=&quot;&quot; selected>Please Select</option>
 
Makes no difference. Either way CF allows the user to not select anything on the drop down and happily passes &quot;null&quot; or &quot;&quot;.

I'm passing null so that I can check it later, but I want it checked in the browser really, manually coding it with javascript seems klunky. --
John Carratt
 
Well, I haven't used cfform stuff very much, but worth a shot.

I believe you can put your own javascript functions to check onsubmit of the form -- here is what I use on my select lists: (where frm1 is the name of the form and selectFieldName is the name of the select list)

<script language=&quot;JavaScript&quot;>
function checkForm()
{
if (document.frm1.selectFieldName.options[document.frm1.selectFieldName.options.selectedIndex].value == '')
{
alert(&quot;Please select something&quot;);
}
}


</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top