Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get script to work inside form. 2

Status
Not open for further replies.

AMysticWeb

Technical User
Oct 20, 2002
309
US
Ok Java Gurus

I modified a script and it works fine all by itself.

But, when I surround it with <Form> tags, I consistently get an error that txtbox is undefined.


The script is below. I think it needs something like this.form or my.form but I really am butt dumb when it comes to script.
---------------------------------------

<SCRIPT LANGUAGE=Javascript>

function disable(OnOff) {
txtbox.disabled=OnOff;
Card_Type.disabled=OnOff;
Exp_Month.disabled=OnOff;
Exp_Year.disabled=OnOff;

}
</SCRIPT>
<!-- this is the text box to enable/disable -->Pay
With
Credit
Card
Yes <INPUT TYPE="Radio" VALUE='ENABLE' onClick=disable(false); name="Card">
No <INPUT TYPE="Radio" VALUE='DISABLE' onClick=disable(true); name="Card">
<p>

If
Yes
Enter
card
number
<input name="txtbox" value=""size="20">
<p>

Card
Type
<select size="1" name="Card_Type">
<option value="Master Card">Master
Card</option>
<option value="Visa">Visa</option>
<option value="Discover">Discover</option>
</select>
<p>

Expiration
Date&nbsp;&nbsp;
<select size="1" name="Exp_Month">
<option selected>Month</option>
<option>_________</option>
<option value="01">01</option>
<option value="02">02</option>
<option value="03">03</option>
<option value="04">04</option>
<option value="05">05</option>
<option value="06">06</option>
<option value="07">07</option>
<option value="08">08</option>
<option value="09">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>&nbsp;&nbsp;&nbsp;
&nbsp;<select size="1" name="Exp_Year">
<option selected>Year</option>
<option>________</option>

<option value="2004">2004</option>
<option value="2005">2005</option>
<option value="2006">2006</option>
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009">2009</option>
<option value="2010">2010</option>

</select>

---------------------------------------

Please advise,
Thanks for taking the time to take a look.

Micheal

Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 
try changing

function disable(OnOff) {
txtbox.disabled=OnOff;
Card_Type.disabled=OnOff;
Exp_Month.disabled=OnOff;
Exp_Year.disabled=OnOff;

}

to

function disable(OnOff) {
var f = document.forms[0];
f.txtbox.disabled=OnOff;
f.Card_Type.disabled=OnOff;
f.Exp_Month.disabled=OnOff;
f.Exp_Year.disabled=OnOff;

}

=========================================================
-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
 
Hi Jeff,

Thanks for the quick response. I still get the same error.

But,with your help, changed

function disable(OnOff) {
var f = document.forms[0];
f.txtbox.disabled=OnOff;
f.Card_Type.disabled=OnOff;
f.Exp_Month.disabled=OnOff;
f.Exp_Year.disabled=OnOff;


to

function disable(OnOff) {
var f = myform;
f.txtbox.disabled=OnOff;
f.Card_Type.disabled=OnOff;
f.Exp_Month.disabled=OnOff;
f.Exp_Year.disabled=OnOff;

I kept thinking it had something to do with myform or thisform.

Thanks a lot, you got me heading in the right direction.

Micheal

Hope I have been of some help,
Micheal

FrontPage Form Tutorials & Form Script Examples
 
Using

Code:
var f = myform;

Will only work if your form has a name of "myform" - and regardless, you should use something like this instead to keep up cross-browser compatibility:

Code:
var f = document.forms['myform'];

Or, as Jeff suggested,

Code:
var f = document.forms[0];

(assuming your form is the first form on the page).

Dan

 
Dan,

congratulations on your 100th javascript star

-kaht

banghead.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top