Connecting Tech Pros Worldwide Help | Site Map

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

Matt Herson
Guest
 
Posts: n/a
#1: Jul 20 '05
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="javascript:sendOrnot()"><img
src="../../../images/request_info_submit_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_submit_submitImg.gif"
onclick="this.form.form-name.value='request_for_info';this.form.sendOrnot( )"[color=blue]
>[/color]

<input type="image"
src="../../../images/request_info_submit_ver2_submitImg.gif"onclick="th is.fo
rm.form-name.value='request_for_info_ver2';this.form.this. form.sendOrnot()">

</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


Wim Poorten
Guest
 
Posts: n/a
#2: Jul 20 '05

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


Matt Herson wrote:[color=blue]
> <form>
>
> <input type="hidden" name="form-name" value="">
>
> <input type="image"
> src="../../../images/request_info_submit_submitImg.gif"
>[/color]
onclick="this.form.form-name.value='request_for_info';this.form.sendOrnot( )"[color=blue][color=green]
>>[/color]
>
> <input type="image"
>[/color]
src="../../../images/request_info_submit_ver2_submitImg.gif"onclick="th is.fo[color=blue]
>[/color]
rm.form-name.value='request_for_info_ver2';this.form.this. form.sendOrnot()">[color=blue]
>
> </form>
>
> Doing so, gave me an invalid form error.[/color]

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


Richard Cornford
Guest
 
Posts: n/a
#3: Jul 20 '05

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


"Wim Poorten" <invalid@nohost.com> wrote in message
news:P9Sdb.4508$Il4.923916441@hestia.telenet-ops.be...
<snip>[color=blue]
>The dash is not allowed in the name of a control.
>Change "form-name" into "form_name".[/color]
<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.


Matt Herson
Guest
 
Posts: n/a
#4: Jul 20 '05

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


ok, assuming the dash is accepted, any ideas on how to accomplish the change
to the hidden field?


"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message
news:bl9g77$efq$1$8300dec7@news.demon.co.uk...[color=blue]
> "Wim Poorten" <invalid@nohost.com> wrote in message
> news:P9Sdb.4508$Il4.923916441@hestia.telenet-ops.be...
> <snip>[color=green]
> >The dash is not allowed in the name of a control.
> >Change "form-name" into "form_name".[/color]
> <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.
>
>[/color]


Richard Cornford
Guest
 
Posts: n/a
#5: Jul 20 '05

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


"Matt Herson" <ebay2@mherson.com> wrote in message
news:bl9j0e$37d$1@bob.news.rcn.net...[color=blue]
> ok, assuming the dash is accepted, any ideas on how to accomplish the[/color]
change[color=blue]
> to the hidden field?[/color]
<snip>[color=blue][color=green]
>><URL: http://jibbering.com/faq/#FAQ4_25 >
>>-and-
>><URL: http://jibbering.com/faq/#FAQ4_39 >[/color][/color]
<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&submit1.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.


Matt Herson
Guest
 
Posts: n/a
#6: Jul 20 '05

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


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="javascript:sendOrnot()"><img
src="../../../images/request_info_submit_submitImg.gif" border="0"></a>
but pass the hidden values at the same time

Any ideas??



"Richard Cornford" <Richard@litotes.demon.co.uk> wrote in message
news:bl9url$9sk$1$8300dec7@news.demon.co.uk...[color=blue]
> "Matt Herson" <ebay2@mherson.com> wrote in message
> news:bl9j0e$37d$1@bob.news.rcn.net...[color=green]
> > ok, assuming the dash is accepted, any ideas on how to accomplish the[/color]
> change[color=green]
> > to the hidden field?[/color]
> <snip>[color=green][color=darkred]
> >><URL: http://jibbering.com/faq/#FAQ4_25 >
> >>-and-
> >><URL: http://jibbering.com/faq/#FAQ4_39 >[/color][/color]
> <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&submit1.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.
>
>[/color]


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#7: Jul 20 '05

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


"Matt Herson" <ebay2@mherson.com> writes:

Please don't top post.
[color=blue]
> The validation script that has been developed will not support input
> type=image tags for the submit button.[/color]

Ok, then how about:

<button type="submit" name="submit1"><img src="..."></button>
[color=blue]
> It needs to be done within an <a> tag. So, I need to use the link
> like:[/color]

Who says that it *needs* that? Maybe there is another way?
[color=blue]
> <a href="javascript:sendOrnot()"><img
> src="../../../images/request_info_submit_submitImg.gif" border="0"></a>[/color]

At lease use the onclick attribute instead of a javascript: pseudo
protocol.
[color=blue]
> but pass the hidden values at the same time[/color]

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

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Stephen
Guest
 
Posts: n/a
#8: Jul 20 '05

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


Richard Cornford wrote:
[color=blue]
> "Matt Herson" <ebay2@mherson.com> wrote in message
> news:bl9j0e$37d$1@bob.news.rcn.net...
>[color=green]
>>ok, assuming the dash is accepted, any ideas on how to accomplish the[/color]
>
> change
>[color=green]
>>to the hidden field?[/color]
>
> <snip>
>[color=green][color=darkred]
>>><URL: http://jibbering.com/faq/#FAQ4_25 >
>>>-and-
>>><URL: http://jibbering.com/faq/#FAQ4_39 >[/color][/color]
>
> <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...][/color]

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_for_info"
name="request_for_info_ver2"

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

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

Regards,
Stephen



Matt Herson
Guest
 
Posts: n/a
#9: Jul 20 '05

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



"Stephen" <ssansom@austin.rr.com> wrote in message
news:Sk0eb.171145$834.125131@twister.austin.rr.com ...[color=blue]
> Richard Cornford wrote:
>[color=green]
> > "Matt Herson" <ebay2@mherson.com> wrote in message
> > news:bl9j0e$37d$1@bob.news.rcn.net...
> >[color=darkred]
> >>ok, assuming the dash is accepted, any ideas on how to accomplish the[/color]
> >
> > change
> >[color=darkred]
> >>to the hidden field?[/color]
> >
> > <snip>
> >[color=darkred]
> >>><URL: http://jibbering.com/faq/#FAQ4_25 >
> >>>-and-
> >>><URL: http://jibbering.com/faq/#FAQ4_39 >[/color]
> >
> > <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...][/color]
>
> 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_for_info"
> name="request_for_info_ver2"
>
> At least this way, "everybody" transmits the same thing on submit.
>
> I definitely agree this is the way to go ...
>
> Regards,
> Stephen
>
>
>[/color]
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.


Closed Thread