469,579 Members | 1,214 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

change hidden input value

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.

The function looks like

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
document.theForm.theName.value = theValue;
document.theForm.submit();
}
</script>

The form looks like

<form action="product/details" method="post" name="catxml" />
<input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml, familyid, '456');">Product
1</a>
</form>

The error reports that 'familyid is undefined'.

Can someone clue me in? Thanks.
Jan 30 '07 #1
4 45490

On Jan 30, 2:35 pm, "Bosconian" <nob...@nowhere.com>
wrote:
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.

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
document.theForm.theName.value = theValue;
theForm [ theName ] . value = theValue ;
document.theForm.submit();
theForm . submit ( ) ;
}
</script>

<form action="product/details" method="post"
name="catxml" />
Utter nonsense. The trailing slash in XML denotes a
childless element. That is, the following two notations are
semantically identical:

<form/>

and

<form></form>

Later on there's a closing tag for the form element in your
document. As it is, it doesn't make any sense--the document
is neither XML nor HTML. I'd strongly advise sticking to
HTML 4.01 Strict, at least until you start getting some
understanding of the matter.
<input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml,
familyid, '456');">Product 1</a>
<a
onclick=
"
submitLink
(
document . forms [ 0 ] , 'familyid', '456'
) ;
">
Product 1
</a>
</form>

The error reports that 'familyid is undefined'.
Naturally. Is familyid defined, after all? Not in the code
snippet you showed us, anyway.
Can someone clue me in? Thanks.
Without meaning to be rude, you managed to demonstrate
appaling ignorance in just a few lines of code. Either read
some good literature on the matter (and I don't mean just
JavaScript, your understanding is obviously just as lacking
where HTML and XML are concerned), find yourself a capable
mentor willing to teach you, or give it up.

--
Pavel Lepin

Jan 30 '07 #2
<p.*****@ctncorp.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
>
On Jan 30, 2:35 pm, "Bosconian" <nob...@nowhere.com>
wrote:
>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.

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
document.theForm.theName.value = theValue;

theForm [ theName ] . value = theValue ;
> document.theForm.submit();

theForm . submit ( ) ;
> }
</script>

<form action="product/details" method="post"
name="catxml" />

Utter nonsense. The trailing slash in XML denotes a
childless element. That is, the following two notations are
semantically identical:

<form/>

and

<form></form>

Later on there's a closing tag for the form element in your
document. As it is, it doesn't make any sense--the document
is neither XML nor HTML. I'd strongly advise sticking to
HTML 4.01 Strict, at least until you start getting some
understanding of the matter.
><input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml,
familyid, '456');">Product 1</a>

<a
onclick=
"
submitLink
(
document . forms [ 0 ] , 'familyid', '456'
) ;
">
Product 1
</a>
></form>

The error reports that 'familyid is undefined'.

Naturally. Is familyid defined, after all? Not in the code
snippet you showed us, anyway.
>Can someone clue me in? Thanks.

Without meaning to be rude, you managed to demonstrate
appaling ignorance in just a few lines of code. Either read
some good literature on the matter (and I don't mean just
JavaScript, your understanding is obviously just as lacking
where HTML and XML are concerned), find yourself a capable
mentor willing to teach you, or give it up.

--
Pavel Lepin
You are right about one thing. I'm a backend developer. We usually leave the
front-end stuff to "webmasters" and HTML jockeys like yourself.

I have to wonder though, why would anyone even bother spending the time to
craft a response like yours?

I suppose one can hardly blame you. You have to go through life with the
name "Pavel Lepin", the guy who got pounded daily in high school and who's
never kissed a girl. I suspect being a webmaster is really the only thing
you're good at. Just keep tell yourself, "chicks dig HTML."

Have a nice day.

Jan 30 '07 #3
<p.*****@ctncorp.comwrote in message
news:11*********************@q2g2000cwa.googlegrou ps.com...
>
On Jan 30, 2:35 pm, "Bosconian" <nob...@nowhere.com>
wrote:
>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.

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
document.theForm.theName.value = theValue;

theForm [ theName ] . value = theValue ;
> document.theForm.submit();

theForm . submit ( ) ;
> }
</script>

<form action="product/details" method="post"
name="catxml" />

Utter nonsense. The trailing slash in XML denotes a
childless element. That is, the following two notations are
semantically identical:

<form/>

and

<form></form>

Later on there's a closing tag for the form element in your
document. As it is, it doesn't make any sense--the document
is neither XML nor HTML. I'd strongly advise sticking to
HTML 4.01 Strict, at least until you start getting some
understanding of the matter.
><input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml,
familyid, '456');">Product 1</a>

<a
onclick=
"
submitLink
(
document . forms [ 0 ] , 'familyid', '456'
) ;
">
Product 1
</a>
></form>

The error reports that 'familyid is undefined'.

Naturally. Is familyid defined, after all? Not in the code
snippet you showed us, anyway.
>Can someone clue me in? Thanks.

Without meaning to be rude, you managed to demonstrate
appaling ignorance in just a few lines of code. Either read
some good literature on the matter (and I don't mean just
JavaScript, your understanding is obviously just as lacking
where HTML and XML are concerned), find yourself a capable
mentor willing to teach you, or give it up.

--
Pavel Lepin
Hi Pavel,

I wanted to let you know that you inspired me "not to suck." As a result of
you being a complete jerk and arrogant asshole, I pushed on ahead and
discover the error in my ways.

Best of luck belittling future posters and here's hoping you get laid
someday.
Jan 30 '07 #4

"Bosconian" <no****@nowhere.comwrote in message
news:lc******************************@comcast.com. ..
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.

The function looks like

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
document.theForm.theName.value = theValue;
document.theForm.submit();
}
</script>

The form looks like

<form action="product/details" method="post" name="catxml" />
<input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml, familyid,
'456');">Product 1</a>
</form>

The error reports that 'familyid is undefined'.

Can someone clue me in? Thanks.
For those of you playing along at home, here's how the code ended up:

<script type='text/javascript'>
function submitLink(theForm, theName, theValue) {
theForm.elements[theName].value = theValue;
theForm.submit();
}
</script>

<form action="product/details" method="post" name="catxml">
<input type="hidden" name="familyid" value="" />
<a href="javascript: submitLink(document.catxml, 'familyid',
'455');">Product 1</a>
</form>

I made two corrections:

1) The first parameter in the function call already included the document
object and the duplicate was removed from within the function.
2) The second parameter is a variable string reference of the form element
and needed to be handled as such.

As it turns out, familyid was indeed defined and clearly evident in the
form--it just wasn't being referenced properly.

Lessons learned:

1) Coding while sleep-deprived only leads to sloppy mistakes and oversights.
2) Ignore arrogant assholes who have nothing to contribute to the community
except unconstructive criticism and negativity.

While on the subject, Pavel evidently thought the code was XML because the
opening form tag had a trailing slash (which, while incorrect, is
subsequently ignored by the brower) and the form is named "CatXML".

Poor pathetic Pavel. :-(
Jan 30 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Wim Roffal | last post: by
2 posts views Thread by juglesh | last post: by
5 posts views Thread by John Oliver | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.