开发者

JQuery Validate Mutli Select

开发者 https://www.devze.com 2023-04-01 02:28 出处:网络
I have following HTML and I am using JQuery Validation plugin. I want it so that if user selects first option \"Select\" it should not allow to post form.But its not working anyone knows why ? Its wor

I have following HTML and I am using JQuery Validation plugin. I want it so that if user selects first option "Select" it should not allow to post form.But its not working anyone knows why ? Its working fine for Select Dropdown but not wit multiple="multiple".

<select multiple="multiple" size="2">
  <option value="">Select</option>
  <option value="volvo">Volvo</option>
  <option value="saab">Saab</option>
  <option value=开发者_C百科"mercedes">Mercedes</option>
  <option value="audi">Audi</option>
</select>


The jQuery .val() method returns an array containing each selected option when working with elements. If no items are selected it'll return an empty array, and if the first item you listed is selected then the array will contain a single item that has a value of "".

You could try this instead:

<select multiple="multiple" size="2"> 
  <option></option> 
  <option value="volvo">Volvo</option> 
  <option value="saab">Saab</option> 
  <option value="mercedes">Mercedes</option> 
  <option value="audi">Audi</option> 
</select>

However, since it's a multiple select, do you really need a blank item anyway?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号