Spencer Alger
Spencer Alger

Reputation: 958

HTML Input is not updating value attribute on change

OOPS, Since the "name" field was at the top it was the one I was testing with, and it turned out that was the only one with an issue. Must have something to do with using "name" as the name...


For some reason the input tags in my form are not updating the value attribute when they are changed view the actual element (not JavaScript). The data posted to the server is the original value of the "value" attribute, not the text in the textbox.

The textareas in the form work fine, and I have checked javascript fired "onchange" and I can't find any... Help please!

Here is the HTML:

<form action="" method="post">
<div id="group-1" class="group case">
  <a class="heading open">heading</a>
  <input name="editform[0][class]" value="case" type="hidden">
  <input name="editform[0][id]" value="2" type="hidden">
  <div class="field">
    <label>Name</label>
    <input class="text" name="editform[0][name]" value="Mike Escarcaga" type="text" >
  </div>
  <div class="field">
    <label>Title</label>
    <input class="text" name="editform[0][title]" value="General Manager" type="text" >
  </div>
  <!-- repeated for each field -->
  <div class="field" >
    <label >Text</label>
    <textarea class="ltext" name="editform[0][text]" >
      Blah HTML, and more blah...
    </textarea>
  </div>
</div>
<!-- repeated for each group in the form (editform[1], editform[2], etc.) -->
</form>

Upvotes: 16

Views: 72744

Answers (3)

Mr Talha
Mr Talha

Reputation: 825

I agree with @Quentin. The DOM contains the live value and the HMTL input contains the default value for an input. To change the default value of the input, set an element's defaultValue property:

document.getElementById("myText").defaultValue = "Goofy";

Upvotes: 10

user2340939
user2340939

Reputation: 1991

Note that the browser parses the HTML tag element and creates a corresponding DOM node object.

  • "Initial/starting/default value" of input:
    • ONLY the initial value of value attribute of input's HTML tag element.
    • defaultValue property of input's DOM node object.
  • "Current value" of input:
    • value attribute of input's HTML tag element
    • value property of input's DOM node object.

See also: What is the difference between properties and attributes in HTML?

Upvotes: 0

Quentin
Quentin

Reputation: 944455

The value attribute contains the default value for an input, not the live value.

The DOM value property contains a live value.

Upvotes: 29

Related Questions