/    Sign up×
Community /Pin to ProfileBookmark

Trouble with HTML input and javascript.

I am very limited in my javascript knowledge. I am trying to pass the value of an input box into a hidden input field but the value just comes up as 0 and not what the person puts in the input box. Here is the code. Btw the onkeyup on the input is used for a different function.

[code=html]
<form name=”order” method=”POST” action=”https://order.store.yahoo.net/yhst-73567813481049/cgi-bin/wg-order?yhst-73567813481049″>

<input onkeyup=”return autocalc(this,quantity1,quantity2,quantity3,quantity4)” name=”quantity0″ type=”text” value=”0″ maxlength=”3″ size=”3″ />
</form>

<script type=”text/javascript”>
jsquantity = document.order.quantity0.value;
document.write(‘<input type=”hidden” name=”vwattr0_Eco Hemp Pinwheel” value=”‘);
document.write(jsquantity);
document.write(‘”>’);
</script>

[/code]

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@DanInMANov 01.2010 — something like this?

[CODE]<form name="order" method="POST" action="https://order.store.yahoo.net/yhst-73567813481049/cgi-bin/wg-order?yhst-73567813481049" onsubmit="setJSQT()">

<input onkeyup="return autocalc(this,quantity1,quantity2,quantity3,quantity4)" name="quantity0" type="text" value="0" maxlength="3" size="3" />
</form>

<script type="text/javascript">
<script type="text/javascript">
function setJSQT()
{
jsquantity = document.order.quantity0.value;
document.write('<input type="hidden" name="vwattr0_Eco Hemp Pinwheel" value="'+jsquantity+'">');
}
</script>
</script>[/CODE]
Copy linkTweet thisAlerts:
@mgoblue4authorNov 01.2010 — Thank you for the help Dan but that didn't seem to work. I copied and pasted the code directly into my site and it didn't even seem to add any of the hidden input to the next page. I just realized that the hidden input must be within the form, is this why it is not working?
Copy linkTweet thisAlerts:
@KorNov 01.2010 — document.write is not a dynamic method. It will rewrite the document. You should use DOM methods to create and append new elements to the DOM.
Copy linkTweet thisAlerts:
@slaughtersNov 01.2010 — You hidden input field name is "vwattr0_Eco Hemp Pinwheel" ?

I do not think that you can use SPACES as part of a form fields name.

Other than that. Do not write out the hidden field HTML. Just type in its HTML on the page.

In your JavaScript function set it's value to be what you retrieved as the value from the other input field (using similar syntax)
Copy linkTweet thisAlerts:
@mgoblue4authorNov 01.2010 — You hidden input field name is "vwattr0_Eco Hemp Pinwheel" ?

I do not think that you can use SPACES as part of a form fields name.

Other than that. Do not write out the hidden field HTML. Just type in its HTML on the page.

In your JavaScript function set it's value to be what you retrieved as the value from the other input field (using similar syntax)[/QUOTE]


Thank you very much for taking time to answer but other then the no spaces thing I really didn't understand what I need to do ?

Would it be possible for you to show me?
Copy linkTweet thisAlerts:
@savvykmsNov 02.2010 — Given:
[code=html]
<form name="test">
<input type="text" name="a" value="0" onclick="setit()">
<input type="hidden" name="b" value="0">
</form>
[/code]
[code=php]
function setit() { document.test.b.value = document.test.a.value; }
[/code]



OR


Given:
[code=html]
<form name="test">
<input type="text" name="a" id="a" value="0" onclick="setit()">
<input type="hidden" name="b" id="b" value="0">
</form>
[/code]
[code=php]
function setit() { document.getElementById("b").value = document.getElementById("a").value; }
[/code]


The hidden field will have the same text as the text field. I'll leave the other computations, logic, and statements to you.
Copy linkTweet thisAlerts:
@slaughtersNov 02.2010 — Thank you very much for taking time to answer but other then the no spaces thing I really didn't understand what I need to do ?

Would it be possible for you to show me?[/QUOTE]


This
[code=html]<input type="hidden" name="vwattr0_Eco_Hemp_Pinwheel">[/code]

Not this:
[code=html]<input type="hidden" name="vwattr0_Eco Hemp Pinwheel">[/code]
×

Success!

Help @mgoblue4 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...