/    Sign up×
Community /Pin to ProfileBookmark

Script program string into hidden form fields

Hello,

I have a text box in a Frontpage form. This form has several hidden fields also. This form is submitted to a CGI script. Thus the hidden fields appear, and the text also in the CGI page. However, I would like the hidden fields to use information from the Text Box. How would I put a variable into a hidden field. It is a small Java script program that modifies the string the user inputs.

Here it is: (I get no errors, not sure if its right though)
———————————————–

<SCRIPT language=Javascript>
<!–
function description() {
string = eval(document.order.name.value);
var shaftsize;
var i = 0;
while ( i < name.length() ) {
if ( ( name.charAt(2) + name.charAt(3) ) == 03 )
*****shaftsize = “Shaft Size: 1/2 inch”; ***(this right?)
}
document.submitform.custom2.value=shaftsize;
return custom2;
}
// –>

</SCRIPT>
—————————————————-

The form part is as follows:
—————————————————-

<FORM NAME=order METHOD=POST ACTION=”http://www.————.com/cgi/cart.pl”>
<INPUT TYPE=HIDDEN NAME=price VALUE=”121.00″>
<INPUT TYPE=TEXT NAME=name VALUE=”14XX – 01XX – XXXX” SIZE=25 MAXLENGTH=25>

*******<INPUT TYPE=HIDDEN NAME=custom2>******

<INPUT TYPE=SUBMIT NAME=”add” VALUE=”Add To Cart !”>
</FORM>


———————————–

The custom2 variable is a part of the 14XX-01XX-XXXX string. How do I put that into the form????

Thank you very much,

Patrick

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@ExuroAug 09.2003 — Well, here's your code and the comments I had on it:
[code=php]
<SCRIPT language=Javascript>
<!--
function description() {
string = eval(document.order.name.value); // What is this line supposed to do???
var shaftsize;
var i = 0;
while ( i < name.length() ) { // What is this loop for???
if ( ( name.charAt(2) + name.charAt(3) ) == 03 ) // I think a regexp could do this better
shaftsize = "Shaft Size: 1/2 inch"; // that seems right
}
document.submitform.custom2.value=shaftsize; // submitform??? custom2 is in form "order"...
return custom2;
}
// -->
</SCRIPT>
[/code]

After looking through it, I thought you may have been trying for something like this:
[code=php]
<SCRIPT language=Javascript>
<!--
function description() {
var shaftsize;
var str = document.order.name1.value;
if (/^1403/.test(str)) {
shaftsize = "Shaft Size: 1/2 inch";
}
else {
shaftsize = "";
}
document.order.custom2.value=shaftsize;
}
// -->
</SCRIPT>

<INPUT TYPE="text" NAME="name1" VALUE="14XX - 01XX - XXXX"
SIZE="25" MAXLENGTH="25" onchange="description()">
[/code]

I changed "name" to "name1" in my example because "name" is an actual property... Well, I hope that helps!
Copy linkTweet thisAlerts:
@delldimensionauthorAug 10.2003 — Thanks from your friendly neighbour up north!!!

Patrick
×

Success!

Help @delldimension 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.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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