473,889 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to change the value of a hidden form value on submit

I have been trying to find a way to use JavaScript to change the value of a
hidden field on submit. I am already invoking a JavaScript to handle the
validation on submit.

The reason I need to change this field is some of the forms have two buttons
on them, each needs to process the form differently. If I can change the
value of the hidden field dynamically it will solve my issue as I can run
each against a diffent cgi.

Currently my submit button looks like:

<a href="javascrip t:sendOrnot()"> <img
src="../../../images/request_info_su bmit_submitImg. gif" border="0"></a>

I need one button to pass the value of:

<input type=hidden name=form-name value="request_ for_info">

And the other as:

<input type=hidden name=form-name value="request_ for_info_ver2">

I have tried using something like:

<form>

<input type="hidden" name="form-name" value="">

<input type="image" src="../../../images/request_info_su bmit_submitImg. gif"
onclick="this.f orm.form-name.value='req uest_for_info'; this.form.sendO rnot()"


<input type="image"
src="../../../images/request_info_su bmit_ver2_submi tImg.gif"onclic k="this.fo
rm.form-name.value='req uest_for_info_v er2';this.form. this.form.sendO rnot()">

</form>

Doing so, gave me an invalid form error.

Any ideas on how I could accomplish this. I have done a lot of looking on
the web and have tried many things but have not had any luck. Any help would
be extremly appreciated. In addition to passing the changed value for
form-name, I also still need to invoke the JavaScript used for my
validation.

Thanks,

Matt
Jul 20 '05 #1
8 17310
Matt Herson wrote:
<form>

<input type="hidden" name="form-name" value="">

<input type="image"
src="../../../images/request_info_su bmit_submitImg. gif"
onclick="this.f orm.form-name.value='req uest_for_info'; this.form.sendO rnot()"


<input type="image"

src="../../../images/request_info_su bmit_ver2_submi tImg.gif"onclic k="this.fo rm.form-name.value='req uest_for_info_v er2';this.form. this.form.sendO rnot()">
</form>

Doing so, gave me an invalid form error.


The dash is not allowed in the name of a control.
Change "form-name" into "form_name" .

I guess the "this.form.this .form.sendOrnot ()" for the second image is a
typo.

--

Wim Poorten
Jul 20 '05 #2
"Wim Poorten" <in*****@nohost .com> wrote in message
news:P9******** **************@ hestia.telenet-ops.be...
<snip>
The dash is not allowed in the name of a control.
Change "form-name" into "form_name" .

<snip>

The dash is allowed in the name of a control.

From the HTML specification:-
<quote>
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").
</quote>

The dash is not allowed in a JavaScript identifier and only valid
JavaScript identifiers are allowed within dot notation property
accessors. Bracket notation property accessors should be a viable
alternative in this case:-

<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >

Richard.
Jul 20 '05 #3
ok, assuming the dash is accepted, any ideas on how to accomplish the change
to the hidden field?
"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:bl******** ***********@new s.demon.co.uk.. .
"Wim Poorten" <in*****@nohost .com> wrote in message
news:P9******** **************@ hestia.telenet-ops.be...
<snip>
The dash is not allowed in the name of a control.
Change "form-name" into "form_name" .

<snip>

The dash is allowed in the name of a control.

From the HTML specification:-
<quote>
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be
followed by any number of letters, digits ([0-9]), hyphens ("-"),
underscores ("_"), colons (":"), and periods (".").
</quote>

The dash is not allowed in a JavaScript identifier and only valid
JavaScript identifiers are allowed within dot notation property
accessors. Bracket notation property accessors should be a viable
alternative in this case:-

<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >

Richard.

Jul 20 '05 #4
"Matt Herson" <eb***@mherson. com> wrote in message
news:bl******** **@bob.news.rcn .net...
ok, assuming the dash is accepted, any ideas on how to accomplish the change to the hidden field?

<snip>
<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >

<snip>

The whole task is unnecessary as <input type="image"> elements provide
name/value pairs in the request if they are given name attributes. Two
buttons with unique names would allow the button that was actually
clicked to be determined on the server by testing for the presence of a
value of each name (the name/value pairs will not be present for the
button that was not clicked).

For an <input type="image"> element the name value pairs are not the
same as with a normal submit button as they include the XY co-ordinates
of the mouse click. Given an element:-

<input type="image" name="submit1" src="[...].gif">

- the query string sent with a get request would be -
?submit1.x=0&su bmit1.y=0 - (similar information can be extracted from
post requests). Branching the code on the server based on this
information is trivial.

Otherwise, if you insist on making this dependent on JavaScript, you
will need to switch to setting the value of the hidden filed using a
bracket notation property accessor to avoid the invalid (for a
JavaScript identifier) characters in the field name. You will also nee
to cancel the default action of the <input type="submit"> buttons (which
is to submit the form), or cancel the submission of the form from the
onsubmit handler.

Richard.
Jul 20 '05 #5
The validation script that has been developed will not support input
type=image tags for the submit button. It needs to be done within an <a>
tag. So, I need to use the link like:
<a href="javascrip t:sendOrnot()"> <img
src="../../../images/request_info_su bmit_submitImg. gif" border="0"></a>
but pass the hidden values at the same time

Any ideas??

"Richard Cornford" <Ri*****@litote s.demon.co.uk> wrote in message
news:bl******** ***********@new s.demon.co.uk.. .
"Matt Herson" <eb***@mherson. com> wrote in message
news:bl******** **@bob.news.rcn .net...
ok, assuming the dash is accepted, any ideas on how to accomplish the

change
to the hidden field?

<snip>
<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >

<snip>

The whole task is unnecessary as <input type="image"> elements provide
name/value pairs in the request if they are given name attributes. Two
buttons with unique names would allow the button that was actually
clicked to be determined on the server by testing for the presence of a
value of each name (the name/value pairs will not be present for the
button that was not clicked).

For an <input type="image"> element the name value pairs are not the
same as with a normal submit button as they include the XY co-ordinates
of the mouse click. Given an element:-

<input type="image" name="submit1" src="[...].gif">

- the query string sent with a get request would be -
?submit1.x=0&su bmit1.y=0 - (similar information can be extracted from
post requests). Branching the code on the server based on this
information is trivial.

Otherwise, if you insist on making this dependent on JavaScript, you
will need to switch to setting the value of the hidden filed using a
bracket notation property accessor to avoid the invalid (for a
JavaScript identifier) characters in the field name. You will also nee
to cancel the default action of the <input type="submit"> buttons (which
is to submit the form), or cancel the submission of the form from the
onsubmit handler.

Richard.

Jul 20 '05 #6
"Matt Herson" <eb***@mherson. com> writes:

Please don't top post.
The validation script that has been developed will not support input
type=image tags for the submit button.
Ok, then how about:

<button type="submit" name="submit1"> <img src="..."></button>
It needs to be done within an <a> tag. So, I need to use the link
like:
Who says that it *needs* that? Maybe there is another way?
<a href="javascrip t:sendOrnot()"> <img
src="../../../images/request_info_su bmit_submitImg. gif" border="0"></a>
At lease use the onclick attribute instead of a javascript: pseudo
protocol.
but pass the hidden values at the same time


Make a hidden field and populate them with the values you want, as
Richard Cornford said.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Richard Cornford wrote:
"Matt Herson" <eb***@mherson. com> wrote in message
news:bl******** **@bob.news.rcn .net...
ok, assuming the dash is accepted, any ideas on how to accomplish the


change
to the hidden field?


<snip>
<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >


<snip>

The whole task is unnecessary as <input type="image"> elements provide
name/value pairs in the request if they are given name attributes. Two
buttons with unique names would allow the button that was actually
clicked to be determined on the server by testing for the presence of a
value of each name (the name/value pairs will not be present for the
button that was not clicked).

[...snip subsequent...]


Most browsers I tested (3 gecko-based + ie6) would do this with buttons
having the same name but different values, e.g.,

name="form-name"
value="request_ for_info"

name="form-name"
value="request_ for_info_ver2"

This *should* work per W3 specs as I understand them. However, I tried
this with opera 7.11, which seemed to omit the name=value pair, even
though it transmits the image click coordinates just fine--as, for
example, "form-name.x=8&form-name.y=9". Unless I'm just looney and
didn't see it correctly. This seems to me to be incorrect following of
the specs. It's certainly different from the way "everybody else" does it.

So I guess you probably would be better off with two different names for
the buttons:

name="request_f or_info"
name="request_f or_info_ver2"

At least this way, "everybody" transmits the same thing on submit.

I definitely agree this is the way to go ...

Regards,
Stephen

Jul 20 '05 #8

"Stephen" <ss*****@austin .rr.com> wrote in message
news:Sk******** *************@t wister.austin.r r.com...
Richard Cornford wrote:
"Matt Herson" <eb***@mherson. com> wrote in message
news:bl******** **@bob.news.rcn .net...
ok, assuming the dash is accepted, any ideas on how to accomplish the


change
to the hidden field?


<snip>
<URL: http://jibbering.com/faq/#FAQ4_25 >
-and-
<URL: http://jibbering.com/faq/#FAQ4_39 >


<snip>

The whole task is unnecessary as <input type="image"> elements provide
name/value pairs in the request if they are given name attributes. Two
buttons with unique names would allow the button that was actually
clicked to be determined on the server by testing for the presence of a
value of each name (the name/value pairs will not be present for the
button that was not clicked).

[...snip subsequent...]


Most browsers I tested (3 gecko-based + ie6) would do this with buttons
having the same name but different values, e.g.,

name="form-name"
value="request_ for_info"

name="form-name"
value="request_ for_info_ver2"

This *should* work per W3 specs as I understand them. However, I tried
this with opera 7.11, which seemed to omit the name=value pair, even
though it transmits the image click coordinates just fine--as, for
example, "form-name.x=8&form-name.y=9". Unless I'm just looney and
didn't see it correctly. This seems to me to be incorrect following of
the specs. It's certainly different from the way "everybody else" does it.

So I guess you probably would be better off with two different names for
the buttons:

name="request_f or_info"
name="request_f or_info_ver2"

At least this way, "everybody" transmits the same thing on submit.

I definitely agree this is the way to go ...

Regards,
Stephen

THANKS TO YOU ALL!
Now, as it turns out the validator I was using won't work anyway. So I no
longer need to submit using the <a href x> tag. Thanks again. Now I will
be posting a validation issue.
Jul 20 '05 #9

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

Similar topics

4
3626
by: Christiaan | last post by:
I am trying to create a small javascript to change the button text and then submit it and do all kinds of form validations. So I have a button with the value "Save", when the button is clicked it should change into "Are you sure" and when you then click the button the form must be submitted. I know this is possible using a simple dialog box but I want to this it this way. This is what I already have, if you have any suggestions please...
2
12878
by: juglesh | last post by:
hi, all, thanks for reading. i have a form in which i want drop down boxes to dynamically change some hidden fields: http://cynthialoganjewelry.com/test4.htm <form name=test method="post" > Pearl Color: <select name="product1">
2
2863
by: Cady | last post by:
I'm trying to do an automatic signup for a newsletter hosted on a separate site. The original page is to sign up to receive a catalog by mail, with an option to signup for an e-newsletter. All of the information is validated when the user clicks submit. At this point a second page is opened (thanking them for their request) and the information previously entered is hidden in a form to be submitted to the e-newsletter service provider....
4
45853
by: Bosconian | last post by:
I've been fighting with this for an hour. My form contains a hidden input with the value initially set to "". When a user clicks on the link, a function is called that updates the hidden form value and submits the form. Unfortunately this generates an error which states the form object is undefined.
5
5706
by: Simon Benson | last post by:
Probably a fairly simple problem but one that's been plaguing me for a couple of days... can anyone help? I have a classic ASP page with a number of text boxes which are updatable. For convenience I want to add 'tabs' at the top of the page (like a card index) as the data to be displayed is split into specific groups (client, company, preferences, events). How do I update any changes to the data and switch to a different page - at
2
22015
by: mcdoublev | last post by:
Hi guys, I don't know whether this is a HTML or Javascript question, but i decided to put it here. This is my problem: I am making a simple HTML form that posts a random number (generated by Javascript) on my website, but I'm having trouble assigning the random number to the form. This is what I have right now:
1
2139
by: webandwe | last post by:
Hi, Can somebody please show me how to change the connection so I can make it work with my MYSQL database... I just need this login to work then I'm done wiht my project. I don't know what is going on here and is, this far from throughing my laptop into the wall..... I want to change cStr = "DRIVER={Microsoft Access Driver (*.mdb)};" cStr = cStr & "DBQ=" & Server.MapPath("\path\to\database.mdb") & ";" Conn.Open(cStr)
5
4476
by: thatcollegeguy | last post by:
Below are my 3php and 2js files. I create a table using ajax/php and then want to change the values in the tables add(+ number for teamid) id's for each specific td in the table. I don't know if I have the entirely wrong approach, but my code is below. Any or all help is appreciated! What currently happens is that the getdivision.php script works perfectly and gives me an entire table of correct data. The problem is that when I click...
0
9966
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11199
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
10791
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
10894
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
10442
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...
1
7997
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5830
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...
1
4647
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3256
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.