Click to See Complete Forum and Search --> : Script program string into hidden form fields


delldimension
08-09-2003, 08:15 AM
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

Exuro
08-09-2003, 11:58 AM
Well, here's your code and the comments I had on it:

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

After looking through it, I thought you may have been trying for something like this:

<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()">

I changed "name" to "name1" in my example because "name" is an actual property... Well, I hope that helps!

delldimension
08-09-2003, 07:15 PM
Thanks from your friendly neighbour up north!!!

Patrick