473,725 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't reset a hidden field in form

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

Aug 12 '07 #1
11 7417
newbie said the following on 8/12/2007 5:26 PM:
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?
Safari and IE on Windows reset it to 0, Firefox and Opera do not. So I
am going to guess you are testing in Firefox. Why it doesn't reset the
value when you reset the form, I do not know. I do know that if you make
the input type="text" and then use CSS to make it "hidden", then FF and
Opera will reset it:

<input type="text" name="IsChanged " value="0" style="display: hidden">

Then it is "hidden" by CSS but Opera9, FF2.0, IE7 and Safari/Win will
reset it to 0.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 12 '07 #2
Evertjan. said the following on 8/12/2007 5:54 PM:
newbie wrote on 12 aug 2007 in comp.lang.javas cript:
>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?
<snip>
Works fine here [IE7]
Works fine in IE7 and Safari3.0 but not in Firefox1.5/2.0 nor Opera9.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 12 '07 #3
RobG wrote on 13 aug 2007 in comp.lang.javas cript:
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 programmaticall y changing the value
attribute should change the defaultValue property for hidden controls
only:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#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 manipulateHidde nFieldsAsRequir ed(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)
Aug 13 '07 #4
Evertjan. said the following on 8/13/2007 3:40 AM:
RobG wrote on 13 aug 2007 in comp.lang.javas cript:
>>>I think IE7 and Safari3.0 are in error, logically speaking.
Technicall y 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 programmaticall y changing the value
attribute should change the defaultValue property for hidden controls
only:

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

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".
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 manipulateHidde nFieldsAsRequir ed(this);'>
That I disagree with. If the user wants the form Reset, then it should
be reset *to the state it was in when the form was loaded*. If you want
to track users actions, the simplest way is to put it outside the
current form. Then onsubmit read it into your current form and submit
it. Then you bypass the reset buttons.

BTW, Firefox doesn't "reset" a form if you do a Refresh of the page,
which I also think is dead wrong behavior. And it has nothing to do with
whether JS modified the page or not.
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.
I would think that the idea of having a JS controlled form to begin with
would often not be the "most versatile" solution, would it?

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 13 '07 #5

Evertjan. wrote:
RobG wrote on 13 aug 2007 in comp.lang.javas cript:
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 programmaticall y changing the value
attribute should change the defaultValue property for hidden controls
only:

<URL: http://www.w3.org/TR/DOM-Level-2-HTM...ml#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/...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 manipulateHidde nFieldsAsRequir ed(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

Aug 13 '07 #6
Randy Webb wrote on 13 aug 2007 in comp.lang.javas cript:
>Specificatio n 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=hiddensens e
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)
Aug 13 '07 #7
RobG wrote on 13 aug 2007 in comp.lang.javas cript:
>
Evertjan. wrote:
>RobG wrote on 13 aug 2007 in comp.lang.javas cript:
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 programmaticall y changing
the value attribute should change the defaultValue property for
hidden controls only:

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

Specificatio n 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/...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='retur n manipulateHidde nFieldsAsRequir ed(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)
Aug 13 '07 #8
Evertjan. wrote on 13 aug 2007 in comp.lang.javas cript:
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)
Aug 13 '07 #9
Evertjan. said the following on 8/13/2007 5:02 AM:
Randy Webb wrote on 13 aug 2007 in comp.lang.javas cript:
>>Specificati on 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=hiddensens e
is not a control at all.
It doesn't matter to me whether you call it a control, a form element,
or a hotdog. If it is part of the form and you reset the form, then the
form should be reset to the state it was in when the form was loaded.
Otherwise, you have a broken reset button.
It is not even a field.
Sure it is. It is just hidden is all.
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.
Call it what you want, it doesn't change anything. If a user wants to
reset a form, then it should reset the form. Period. But, doing "silly
things" with it like trying to maintain a false state after reset/reload
is the silly thing to try to do.
A reset is ment. meseems, to help the user restart the manual form entry
from scratch.
Not according to the W3C (which I don't much care for).
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.
Then don't make it part of that particular form at the time. Use the
onsubmit event handler of the form and set the input's value. Then you
have no worry whatsoever whether it was reset or not.
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. 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.

Want an input that reset doesn't interfere with? (Your "client date/time"):

var myVariableThatR esettingTheForm WontEverChange = new Date();

<form
onsubmit="this. form.inputThatC anBeResetButWil lHaveTheValueIW antInItWhenTheF ormGetsSubmitte d.value=myVaria bleThatResettin gTheFormWontEve rChange">

Now, how will resetting the form change/impact what that hidden fields
value is?

Just don't let the "I hate MS" crowd know IE got it right and Firefox
got it wrong.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javas cript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 13 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
30108
by: Ken | last post by:
How can I reset the initial form variables that are set with session statements when clicking on a button? I tried this but the function was not called: <?PHP function reset_form($none) { $_SESSION = array(); } ?> <form enctype="multipart/form-data" name="company_info" method="post" action="add_pic.php">
7
2822
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) My code is below. I am getting the following error "MyForm.oNetwork.Value is Null or is not an object". I'm struggling to diagnose what to do next. I'd very much appreciate some help Many thanks <HTML><BODY><FORM NAME="MyForm"...
6
2741
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the work. Nota() - opens new window. fechaNota() - closes the window opened by Nota() here is the code.
6
2748
by: charlie_M | last post by:
I figured out via various help from this forum... EXAMPLE: onClick="document.forms.MYBUTTON.value='SIMPLE';document.forms.submit()" In my CGI I see "MYBUTTON" = "SIMPLE" and this works fine.... except that the element MYBUTTON must exist as a hidden field.
1
2090
by: jmgro | last post by:
I have spent way too much time trying to solve the following problem: I have a datalist with a timer in the footer template. It works wonderfully except when the user pages back, then forward, and the counter is reset. I saw in one of Kevin Spencer's comments not to put the timer in javascript on the load function, but I have to get the script to run before the page is rendered, otherwise my timer is not displayed. I have a flag "Hidden...
6
4890
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of the html page controls the form fields that are required. It doesn't function like it's supposed to and I can leave all the fields blank and it still submits the form. Also I can't get it to transfer the file in the upload section. The file name...
1
1428
Wiccadwitch
by: Wiccadwitch | last post by:
Could someone please help??? I'm using paypal's shopping cart which allows for 2 options (such as colors or sizes). I need up to six options with 40 or so colors to choose from. I tried adding 6 but in paypal.com cart it only displays #'s 1 and 6. 2-5 get cut out. Paypal tech gave a website of www.members.aol.com/paypalhelper and said to create select multiples. I did this but there's still something wrong with my code. I can select...
1
2248
by: mlshoats | last post by:
Hello I am trying to make a log to track questions i answer on little hardware problems. I got most of it working but I am very new to programming anything and just started picking up things. I am trying to figure out how to make it that if I select "Other" from either one of my drop downs that it makes the "Comment" text box mandatory. One of my friends said it was easy but I can't figure it out at all. PLEASE HELP. Here is everything I...
2
3166
by: Mo | last post by:
I am trying to calculate open-account credibility for new customers. I have set up a form in which to enter the feedback from their trade references, but the vars get reset each time the page loads. The page is terms.php, and I intentionally have it processing itself because I need the user to be able to repeatedly enter feedback, or stop at any time, and get results of the compiled avg's regardless. For example (very simplified):...
0
8752
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9401
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9257
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8096
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4517
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.