Home Web Front-end JS Tutorial jquery solution to get the value of the drop-down list to be null_jquery

jquery solution to get the value of the drop-down list to be null_jquery

May 16, 2016 pm 06:09 PM
null drop-down list

I wonder if any of you have encountered such a situation?
When using jquery to get the value of the drop-down list ddl, the string 'null' is returned instead of an empty value. As a result, the parameters obtained are incorrect;
Even if it is judged to be non-null in the background, it still causes Error (for example, null was spelled in when piecing together the SQL).
Let’s analyze it below:
The first situation:

Copy the code The code is as follows:



Second case:
Copy code The code is as follows:


or


We get the value like this in the program:
$("#ddlType").val()
For In the first case, if we have not made a selection, then it returns the null value "", but not the string "null";
In the second case, there are no selectable items in ddl, and there are no in the frontend If it is hardcoded or not bound in the background, if you try to get its value, the string "null" will be returned.
Solution: There is currently no better solution. We can only add judgment (!="null") in the background judgment. Obviously, this is not a good solution.
Some friends on the Internet also provided a method to modify the jquery source file and change the last sentence this.value = val; in the implementation of the val function to this.value = val || "";

If you have any good ideas, please feel free to share them! ! !
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
What do undefined and null mean? What do undefined and null mean? Nov 20, 2023 pm 02:39 PM

In JavaScript, both undefined and null represent the concept of "nothing": 1. undefined represents an uninitialized variable or a non-existent property. When a variable is declared but no value is assigned to it, the value of the variable is undefined , when accessing properties that do not exist in the object, the returned value is also undefined; 2. null represents an empty object reference. In some cases, the object reference can be set to null to release the memory it occupies.

What is the difference between null and NULL in c language What is the difference between null and NULL in c language Sep 22, 2023 am 11:48 AM

The difference between null and NULL in C language is: null is a macro definition in C language, usually used to represent a null pointer, which can be used to initialize pointer variables, or to determine whether the pointer is null in a conditional statement; NULL is a macro definition in C language A predefined constant in , usually used to represent a null value, used to represent a null pointer, null pointer array or null structure pointer.

How to use CSS to create a custom style effect for a drop-down list How to use CSS to create a custom style effect for a drop-down list Oct 26, 2023 pm 12:22 PM

How to use CSS to create a custom style effect for a drop-down list. In web design, the drop-down list (DropdownList) is one of the common interactive elements. It can provide the selection function of options to facilitate user operations. However, the browser's default drop-down list style may not meet the design needs, so you need to use CSS to set a custom style. This article will introduce how to use CSS to create custom style effects for drop-down lists, with specific code examples. Creating the basic HTML structure First, I

What is the difference between null and undefined What is the difference between null and undefined Nov 08, 2023 pm 04:43 PM

The difference between null and undefined is: 1. Semantic meaning; 2. Usage scenarios; 3. Comparison with other values; 4. Relationship with global variables; 5. Relationship with function parameters; 6. Nullability check; 7. Performance considerations; 8. Performance in JSON serialization; 9. Relationship with types. Detailed introduction: 1. Semantic meaning, null usually means knowing that this variable will not have any valid object value, while undefined usually means that the variable has not been assigned a value, or the object does not have this attribute; 2. Usage scenarios, etc.

When to use null and undefined When to use null and undefined Nov 13, 2023 pm 02:11 PM

Both null and undefined indicate a lack of value or an undefined state. Depending on the usage scenario, there are some guiding principles for choosing to use null or undefined: 1. When you need to clearly indicate that a variable is empty or invalid, you can use null; 2. When a variable has been declared but not yet assigned a value, it will be set to undefined by default; 3. When you need to check whether a variable is empty or undefined, use the strict equality operator "===" to determine whether the variable is null or undefined. .

What are the uses of null in java What are the uses of null in java Mar 01, 2024 am 10:10 AM

Usage: 1. Initialize the reference type variable to null, indicating that the variable does not currently point to any object; 2. Set the reference type variable to null, which can release the memory space of the object referenced by the variable and help the garbage collector to recover This object; 3. Use null to check whether a reference is empty. You can avoid the occurrence of NullPointerException by judging whether the reference is null. 4. Use null in conditional judgment to judge whether a reference is empty.

PHP form processing: tips on using multi-select boxes, radio buttons and drop-down lists PHP form processing: tips on using multi-select boxes, radio buttons and drop-down lists Aug 07, 2023 pm 11:29 PM

PHP form processing: Tips for using multi-select boxes, radio buttons and drop-down lists In web development, forms are one of the important ways for users to interact with the website. The multi-select boxes, radio buttons and drop-down lists in the form are some common user input options. This article will introduce how to use PHP to process these form elements and give corresponding code examples. Multi-select box A multi-select box allows the user to select multiple options. In HTML, you can use <inputtype="checkbox"&g

How to remove null from php array How to remove null from php array Dec 23, 2022 am 10:27 AM

How to remove nulls from PHP arrays: 1. Use the "foreach($arr as $k=>$v){...}" method to remove null values ​​from the array; 2. Use the while syntax structure to remove null values; 3. Use The array_filter function filters the array and removes null values.

See all articles