Jquery's solution to getting the value of the drop-down list as null

Source: Internet
Author: User

Do you have such a situation?
When you use jquery to obtain the ddl value of the drop-down list, the returned string is 'null' instead of a null value. As a result, the obtained parameter is incorrect;
Even if it is determined in the background that it is not empty, it still leads to an error (for example, the null is spelled in when the SQL statement is pieced together ).
The following is an analysis:
First case:
Copy codeThe Code is as follows:
<Select id = "ddlType">
<Option value = ""> select </option>
<Option value = "1"> Anhui </option>
......
</Select>

Case 2:
Copy codeThe Code is as follows:
<Select id = "ddlType"> </select>
Or
<Asp: DropDownList ID = "ddlType" runat = "server"> </asp: DropDownList>

The values in the program are as follows:
$ ("# DdlType"). val ()
In the first case, if we do not make a selection, then it returns the null value "", but not the string "null ";
In the second case, there is no option in ddl, And the foreground is not written to death or the background is not bound. If you retrieve the value, the return string "null" is returned ".
Solution: currently, no better solution is found. You can only add a judgment in the background (! = "Null"). Obviously, this is not a good solution.
Another method provided by friends on the Internet is to modify the jquery source file and change this. value = val in the last sentence of the val function to this. value = val | "";

If you have any good ideas, please share them with us !!!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.