How does value attribute work for the html input tag after an edit via the inputbox?
example:
<input type="text" name="test" id="test" value="Hello world" />
this will show an input box with the text "Hello world". If I edit it inputing a new string into the rendered textbox (not via raw code), and then try to get his value using js like this
alert(document.getElementById('test').value)
I'll, correctly, get the NEW value. But if I inspect the element through chrome developer tools (or firebug or anything you prefer), I'll see the same "Hello world" string as it was in the beginning..
Which of the two is the right one? js value or chrome inspector?
Here's the Example Fiddle and here's a screenshot
I came up to this while trying to find a solution to this problem: Classic shop situation, I have a table with X inputs tag , where an user can input the quantity of X items. I need to check if one or more values have changed since the previous value of each input: if the comparison between OLD and NEW val returns that the valuehas changed, I need to update the order. Otherwise there's no need to save/update.
I thought I could use attr. "value" to store the "old" value of the input, but probably was not the best choice..
Can anyone explain this behaviour? It's only a "refresh" problem or is there something else behind?
The multiple attribute is a boolean attribute. When present, it specifies that the user is allowed to enter more than one value in the <input> element. Note: The multiple attribute works with the following input types: email, and file.
You can use the <input> tag with attribute type='number'. This input field allows only numerical values. You can also specify the minimum value and maximum value that should be accepted by this field. Save this answer.
The value attribute is used differently for different input types: For "button", "reset", and "submit" - it defines the text on the button. For "text", "password", and "hidden" - it defines the initial (default) value of the input field.
No, a field element can't have multiple types. The only thing you should leave up to the user is inputting data - you select the types when designing the form. The user will pick which ones they want to fill out - unless you make them required. This can all be accomplished in HTML without scripting.
Both are right, they just show different things.
The DOM value
property gives you the current value.
The HTML value
attribute gives you the default value (the same as the DOM defaultValue
property).
The Chrome DOM inspector shows you attribute values in the HTML view. You have to look at the property view to see the property values.
You can find information in this article.
the value seen in html is the default value the form is loaded with. If you want the DOM also to update then you have to use ele.setAttribute("value", "new value")
If you want to know if a element is changed, the best is to attach a onchange event to the input elements and mark some flag in the change handler to know if the form changed or not.
You can assign a so-called proprietary attribute to the input; for example "oldval" so that you can later compare it with current value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With