can't reset a hidden field in form

Discussion in 'Javascript' started by newbie, Aug 12, 2007.

  1. newbie

    newbie Guest

    i have a form in which a hidden field (initial value as '0', and my
    javascript set it to '1' when an event is trigged).
    In the same form, i have a reset field. But I realized that the hidden
    field is not reset to '0' when i push the
    reset button. If I simply change the node from
    "<input type="hidden" id='IsChanged' value='0'>"
    to
    "<input type="text" id='IsChanged' value='0'>"

    Everything is working as expected (the value is reset to '0' when I
    push the reset button) Why does this happen?

    Thanks
     
    newbie, Aug 12, 2007
    #1
    1. Advertising

  2. newbie

    Evertjan. Guest

    newbie wrote on 12 aug 2007 in comp.lang.javascript:

    > i have a form in which a hidden field (initial value as '0', and my
    > javascript set it to '1' when an event is trigged).
    > In the same form, i have a reset field. But I realized that the hidden
    > field is not reset to '0' when i push the
    > reset button. If I simply change the node from
    > "<input type="hidden" id='IsChanged' value='0'>"
    > to
    > "<input type="text" id='IsChanged' value='0'>"
    >
    > Everything is working as expected (the value is reset to '0' when I
    > push the reset button) Why does this happen?



    ==============
    <form>
    <input type=hidden value='aaa'>
    <input type=reset>
    </form>

    <button
    onclick='alert(document.forms[0].elements[0].value)'>
    show value</button>
    <br>

    <button onclick='document.forms[0].elements[0].value="22222"'>
    set value to 2222</button>
    ==============

    Works fine here [IE7]

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 12, 2007
    #2
    1. Advertising

  3. newbie

    newbie Guest

    On Aug 12, 2:54 pm, "Evertjan." <> wrote:
    > newbie wrote on 12 aug 2007 in comp.lang.javascript:
    >
    > > i have a form in which a hidden field (initial value as '0', and my
    > > javascript set it to '1' when an event is trigged).
    > > In the same form, i have a reset field. But I realized that the hidden
    > > field is not reset to '0' when i push the
    > > reset button. If I simply change the node from
    > > "<input type="hidden" id='IsChanged' value='0'>"
    > > to
    > > "<input type="text" id='IsChanged' value='0'>"

    >
    > > Everything is working as expected (the value is reset to '0' when I
    > > push the reset button) Why does this happen?

    >
    > ==============
    > <form>
    > <input type=hidden value='aaa'>
    > <input type=reset>
    > </form>
    >
    > <button
    > onclick='alert(document.forms[0].elements[0].value)'>
    > show value</button>
    > <br>
    >
    > <button onclick='document.forms[0].elements[0].value="22222"'>
    > set value to 2222</button>
    > ==============
    >
    > Works fine here [IE7]
    >
    > --
    > Evertjan.
    > The Netherlands.
    > (Please change the x'es to dots in my emailaddress)


    I debugged my code with firefox. Yes, my code works on IE(6/7), but
    the weird thing happens on firefox:(
     
    newbie, Aug 12, 2007
    #3
  4. newbie

    Evertjan. Guest

    newbie wrote on 13 aug 2007 in comp.lang.javascript:

    > On Aug 12, 2:54 pm, "Evertjan." <> wrote:
    >> ==============
    >> <form>
    >> <input type=hidden value='aaa'>
    >> <input type=reset>
    >> </form>
    >>
    >> <button
    >> onclick='alert(document.forms[0].elements[0].value)'>
    >> show value</button>
    >> <br>
    >>
    >> <button onclick='document.forms[0].elements[0].value="22222"'>
    >> set value to 2222</button>
    >> ==============
    >>
    >> Works fine here [IE7]
    >>

    >
    > I debugged my code with firefox. Yes, my code works on IE(6/7), but
    > the weird thing happens on firefox:(


    I don't think it is wierd at all.

    A hidden field that is set to another value than the initial one
    by code SHOULD NOT be changed or reset by direct user action.
    The user is not ment to influence the hidden field.

    What would be the use of the "hiddenness" if the user could directly
    influence that?

    Randy Webb wrote on 13 aug 2007 in comp.lang.javascript:
    > Works fine in IE7 and Safari3.0 but not in Firefox1.5/2.0 nor Opera9.


    I think IE7 and Safari3.0 are in error, logically speaking.
    Technically it is a question of specification.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 12, 2007
    #4
  5. newbie

    RobG Guest

    On Aug 13, 8:54 am, Randy Webb <> wrote:
    > Evertjan. said the following on 8/12/2007 6:22 PM:
    >
    >
    >
    > > newbie wrote on 13 aug 2007 in comp.lang.javascript:

    >
    > >> On Aug 12, 2:54 pm, "Evertjan." <> wrote:
    > >>> ==============
    > >>> <form>
    > >>> <input type=hidden value='aaa'>
    > >>> <input type=reset>
    > >>> </form>

    >
    > >>> <button
    > >>> onclick='alert(document.forms[0].elements[0].value)'>
    > >>> show value</button>
    > >>> <br>

    >
    > >>> <button onclick='document.forms[0].elements[0].value="22222"'>
    > >>> set value to 2222</button>
    > >>> ==============

    >
    > >>> Works fine here [IE7]

    >
    > >> I debugged my code with firefox. Yes, my code works on IE(6/7), but
    > >> the weird thing happens on firefox:(

    >
    > > I don't think it is wierd at all.

    >
    > > A hidden field that is set to another value than the initial one
    > > by code SHOULD NOT be changed or reset by direct user action.
    > > The user is not ment to influence the hidden field.

    >
    > > What would be the use of the "hiddenness" if the user could directly
    > > influence that?

    >
    > > Randy Webb wrote on 13 aug 2007 in comp.lang.javascript:
    > >> Works fine in IE7 and Safari3.0 but not in Firefox1.5/2.0 nor Opera9.

    >
    > > I think IE7 and Safari3.0 are in error, logically speaking.
    > > Technically it is a question of specification.

    >
    > Personally, I think IE7 and Safari are right. The user tells the browser
    > "Reset this form" and that is what the browser does. FF and Opera don't
    > do what the user asked it to do.


    I think you're right.

    Resetting the form should set all values back to their initial value
    which is set by the value attribute in the HTML. The initial value is
    stored in the DOM defaultValue property, resetting the form should set
    all controls back to the defaultValue.

    Resetting a form should set all controls back to their defaultValue.
    I don't see anywhere that programmatically changing the value
    attribute should change the defaultValue property for hidden controls
    only:

    <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26091157 >


    --
    Rob
     
    RobG, Aug 13, 2007
    #5
  6. newbie

    Evertjan. Guest

    RobG wrote on 13 aug 2007 in comp.lang.javascript:

    >> > I think IE7 and Safari3.0 are in error, logically speaking.
    >> > Technically it is a question of specification.

    >>
    >> Personally, I think IE7 and Safari are right. The user tells the browser
    >> "Reset this form" and that is what the browser does. FF and Opera don't
    >> do what the user asked it to do.

    >
    > I think you're right.
    >
    > Resetting the form should set all values back to their initial value
    > which is set by the value attribute in the HTML. The initial value is
    > stored in the DOM defaultValue property, resetting the form should set
    > all controls back to the defaultValue.
    >
    > Resetting a form should set all controls back to their defaultValue.
    > I don't see anywhere that programmatically changing the value
    > attribute should change the defaultValue property for hidden controls
    > only:
    >
    > <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26091157 >


    Specification is not neccessarily logical and
    why would you call a hidden field a "control"?

    I think that if the clientside js altered a hidden field,
    it is the responsability of that js [programmer] to reset it or not
    after detecting the user's actions:

    <input type='reset'
    onclick='return manipulateHiddenFieldsAsRequired(this);'>

    btw, the whole idea of using the html reset button function in a js
    governed form is often not the most versatile solution,
    especially in a cross browser environment.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 13, 2007
    #6
  7. newbie

    RobG Guest

    Evertjan. wrote:
    > RobG wrote on 13 aug 2007 in comp.lang.javascript:
    >
    > >> > I think IE7 and Safari3.0 are in error, logically speaking.
    > >> > Technically it is a question of specification.
    > >>
    > >> Personally, I think IE7 and Safari are right. The user tells the browser
    > >> "Reset this form" and that is what the browser does. FF and Opera don't
    > >> do what the user asked it to do.

    > >
    > > I think you're right.
    > >
    > > Resetting the form should set all values back to their initial value
    > > which is set by the value attribute in the HTML. The initial value is
    > > stored in the DOM defaultValue property, resetting the form should set
    > > all controls back to the defaultValue.
    > >
    > > Resetting a form should set all controls back to their defaultValue.
    > > I don't see anywhere that programmatically changing the value
    > > attribute should change the defaultValue property for hidden controls
    > > only:
    > >
    > > <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26091157 >

    >
    > Specification is not neccessarily logical and
    > why would you call a hidden field a "control"?''


    Because that is what it is:

    <URL: http://www.w3.org/TR/html4/interact/forms.html#hidden-control >


    > I think that if the clientside js altered a hidden field,
    > it is the responsability of that js [programmer] to reset it or not
    > after detecting the user's actions:


    That is purely your opinion and seems at odds with the specification:

    "Each control has both an initial value and a current value, both of
    which are character strings... ... a control's "initial value" may be
    specified with the control element's value attribute...

    "The control's "current value" is first set to the initial value.
    Thereafter, the control's current value may be modified through user
    interaction and scripts.

    "A control's initial value does not change. Thus, when a form is
    reset, each control's current value is reset to its initial value. If
    a control does not have an initial value, the effect of a form reset
    on that control is undefined."

    <URL: http://www.w3.org/TR/html4/interact/forms.html#h-17.2 >

    I can't see how anyone can interpret that as requiring hidden controls
    that have been modified by script to also be reset by script.

    > <input type='reset'
    > onclick='return manipulateHiddenFieldsAsRequired(this);'>
    >
    > btw, the whole idea of using the html reset button function in a js
    > governed form is often not the most versatile solution,
    > especially in a cross browser environment.


    Perhaps, depending on the situation. But that is not the issue here,
    it is that some browsers do not reset controls to their initial value
    when the W3C specification states that they should.


    --
    Rob
     
    RobG, Aug 13, 2007
    #7
  8. newbie

    Evertjan. Guest

    Randy Webb wrote on 13 aug 2007 in comp.lang.javascript:

    >> Specification is not neccessarily logical and
    >> why would you call a hidden field a "control"?

    >
    > Because that is what it has come to be called. Rather than a "form
    > field" it is commonly called a "control".
    >


    A hidden "control" in the <input type=hidden> sense
    is not a control at all.

    It is not even a field.

    It is just a form element, and if submitted, a form parameter.

    To do silly "control" things with it, like having the user reset it without
    that user knowing what he or she is resetting, just because you call it a
    controll, seeems an uncontrollable error to me.

    A reset is ment. meseems, to help the user restart the manual form entry
    from scratch.

    How can he or she repopulate an hidden "field"?

    Say the hidden field is filled with the client date/time by js,
    it should not be reset to the possibly empty start value, but kept or
    repopulated with the acutal time. That would be the js'es job.

    In short, resetting a hidden formfield value by the html reset function may
    be according to specs, but is illogical. Misnaming it a "control" dos not
    influence this logic.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 13, 2007
    #8
  9. newbie

    Evertjan. Guest

    RobG wrote on 13 aug 2007 in comp.lang.javascript:

    >
    > Evertjan. wrote:
    >> RobG wrote on 13 aug 2007 in comp.lang.javascript:
    >>
    >> >> > I think IE7 and Safari3.0 are in error, logically speaking.
    >> >> > Technically it is a question of specification.
    >> >>
    >> >> Personally, I think IE7 and Safari are right. The user tells the
    >> >> browser "Reset this form" and that is what the browser does. FF
    >> >> and Opera don't do what the user asked it to do.
    >> >
    >> > I think you're right.
    >> >
    >> > Resetting the form should set all values back to their initial
    >> > value which is set by the value attribute in the HTML. The initial
    >> > value is stored in the DOM defaultValue property, resetting the
    >> > form should set all controls back to the defaultValue.
    >> >
    >> > Resetting a form should set all controls back to their
    >> > defaultValue. I don't see anywhere that programmatically changing
    >> > the value attribute should change the defaultValue property for
    >> > hidden controls only:
    >> >
    >> > <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26091157 >

    >>
    >> Specification is not neccessarily logical and
    >> why would you call a hidden field a "control"?''

    >
    > Because that is what it is:
    >
    > <URL: http://www.w3.org/TR/html4/interact/forms.html#hidden-control >


    No.

    That is what some secification siys it could be names.

    Naming a control you cannot control a control only makes me laugh
    uncontrollably.

    I specified the difference between logic and specification,
    so arguing it must be logical, since it is speciefied that way is
    illogical argumentation.

    >
    >
    >> I think that if the clientside js altered a hidden field,
    >> it is the responsability of that js [programmer] to reset it or not
    >> after detecting the user's actions:

    >
    > That is purely your opinion and seems at odds with the specification:


    Again:
    I specified the difference between logic and specification,
    so arguing it must be logical, and that it is specified that way is
    illogical argumentation.

    > "Each control has both an initial value and a current value, both of
    > which are character strings... ... a control's "initial value" may be
    > specified with the control element's value attribute...
    >
    > "The control's "current value" is first set to the initial value.
    > Thereafter, the control's current value may be modified through user
    > interaction and scripts.
    >
    > "A control's initial value does not change. Thus, when a form is
    > reset, each control's current value is reset to its initial value. If
    > a control does not have an initial value, the effect of a form reset
    > on that control is undefined."
    >
    > <URL: http://www.w3.org/TR/html4/interact/forms.html#h-17.2 >
    >
    > I can't see how anyone can interpret that as requiring hidden controls
    > that have been modified by script to also be reset by script.


    Again:
    I specified the difference between logic and specification,
    so arguing it must be logical, and that is specified that way is
    illogical argumentation.

    >
    >> <input type='reset'
    >> onclick='return manipulateHiddenFieldsAsRequired(this);'>
    >>
    >> btw, the whole idea of using the html reset button function in a js
    >> governed form is often not the most versatile solution,
    >> especially in a cross browser environment.

    >
    > Perhaps, depending on the situation. But that is not the issue here,
    > it is that some browsers do not reset controls to their initial value
    > when the W3C specification states that they should.


    The issue is that I specified the difference between logic and
    specification, so arguing it must be logical, and that is specified that
    way is illogical argumentation.

    You may be defining "the issue" otherwise, but that was not what I was
    arguing.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 13, 2007
    #9
  10. newbie

    Evertjan. Guest

    Evertjan. wrote on 13 aug 2007 in comp.lang.javascript:

    > That is what some secification siys it could be names.


    Since there is no bug in my keyboard,
    it must have been me that wrote that ;-(

    I ment:
    That is what some specification says it could be named.


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 13, 2007
    #10
  11. newbie

    Evertjan. Guest

    Randy Webb wrote on 13 aug 2007 in comp.lang.javascript:
    >> In short, resetting a hidden formfield value by the html reset
    >> function may be according to specs, but is illogical. Misnaming it a
    >> "control" dos not influence this logic.

    >
    > Whether it is illogical or not is a personal opinion.


    No matter, I started that it was illogical, but perhaps in specs.

    > And no matter
    > what that opinion is (mine, yours or anybody else's), the behavior is
    > easily worked around and when there is a trivial solution then it
    > seems moot to even worry about it.


    I think discussing the logic of specifications is a vey good way to
    influence later dicisions of "the people that decide".

    The W3C people must lack the vision of the simple users, like we are.

    An example of logic:
    The logic of any core function trying to parse a number string
    as octal, [without the specific base number as an explicit parameter]
    in this century, escapes me. Backward compatibility has it's limits.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Aug 13, 2007
    #11
  12. newbie

    Guest

    On Aug 12, 8:32 pm, RobG <> wrote:
    > On Aug 13, 8:54 am, Randy Webb <> wrote:
    >
    >
    >
    > > Evertjan. said the following on 8/12/2007 6:22 PM:

    >
    > > > newbie wrote on 13 aug 2007 in comp.lang.javascript:

    >
    > > >> On Aug 12, 2:54 pm, "Evertjan." <> wrote:
    > > >>> ==============
    > > >>> <form>
    > > >>> <input type=hidden value='aaa'>
    > > >>> <input type=reset>
    > > >>> </form>

    >
    > > >>> <button
    > > >>> onclick='alert(document.forms[0].elements[0].value)'>
    > > >>> show value</button>
    > > >>> <br>

    >
    > > >>> <button onclick='document.forms[0].elements[0].value="22222"'>
    > > >>> set value to 2222</button>
    > > >>> ==============

    >
    > > >>> Works fine here [IE7]

    >
    > > >> I debugged my code with firefox. Yes, my code works on IE(6/7), but
    > > >> the weird thing happens on firefox:(

    >
    > > > I don't think it is wierd at all.

    >
    > > > A hidden field that is set to another value than the initial one
    > > > by code SHOULD NOT be changed or reset by direct user action.
    > > > The user is not ment to influence the hidden field.

    >
    > > > What would be the use of the "hiddenness" if the user could directly
    > > > influence that?

    >
    > > > Randy Webb wrote on 13 aug 2007 in comp.lang.javascript:
    > > >> Works fine in IE7 and Safari3.0 but not in Firefox1.5/2.0 nor Opera9.

    >
    > > > I think IE7 and Safari3.0 are in error, logically speaking.
    > > > Technically it is a question of specification.

    >
    > > Personally, I think IE7 and Safari are right. The user tells the browser
    > > "Reset this form" and that is what the browser does. FF and Opera don't
    > > do what the user asked it to do.

    >
    > I think you're right.
    >
    > Resetting the form should set all values back to their initial value
    > which is set by the value attribute in the HTML. The initial value is
    > stored in the DOM defaultValue property, resetting the form should set
    > all controls back to the defaultValue.
    >
    > Resetting a form should set all controls back to their defaultValue.
    > I don't see anywhere that programmatically changing the value
    > attribute should change the defaultValue property for hidden controls
    > only:
    >
    > <URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-26091157>
    >
    > --
    > Rob



    Nail on the head. It is a bug.

    See my comments:

    https://bugzilla.mozilla.org/show_bug.cgi?id=158209

    Please vote for this bug!

    (if you don't already have a bugzilla account, you'll need to
    register. It only takes 2 minutes)

    Discussions on the bugzilla bug are discouraged!

    Further reading material:

    http://www.w3.org/TR/html4/interact/forms.html#h-17.2.1
    ----------------------------------------------------------------
    HTML defines the following control types:
    buttons
    * submit buttons: <snip>
    * reset buttons: When activated, a reset button resets all controls
    to their initial values.
    * push buttons: <snip>
    <snip>
    ....
    checkboxes
    radio buttons
    menus (The SELECT); the OPTGROUP and OPTION.
    text input (INPUT , TEXTAREA)
    file select
    hidden controls
    object controls
    ----------------------------------------------------------------

    Garrett
     
    , Aug 13, 2007
    #12
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rick
    Replies:
    3
    Views:
    8,587
    Alexey Smirnov
    Apr 13, 2010
  2. NotGiven
    Replies:
    3
    Views:
    387
    Michael D. Kersey
    May 13, 2004
  3. GavMc
    Replies:
    4
    Views:
    379
    Evertjan.
    Sep 22, 2005
  4. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    223
  5. Roy Adams
    Replies:
    3
    Views:
    292
    Dr John Stockton
    Dec 21, 2004
Loading...

Share This Page