...

View Full Version : Access A Variable In A Statement



Crashin
03-19-2004, 10:08 PM
I've got the following function:

// function to cancel and return to account display page
function cancel_form(formName) {
document.formName.submit();
}

And the following function call:

<input type="button" name="submitIt" value="Cancel" onclick="return cancel_form('customerSuggestion')">

However, I get the following error when trying to use it:

Error: 'document.formName' is null or not an object

How do I get the function to recognize my form's name in the statement? (Without hard-coding it...)

Thanks for the help!

Garadon
03-19-2004, 10:31 PM
document.forms[formName].submit();

comes to mind

Willy Duitt
03-19-2004, 11:06 PM
this.form or even form since the browser will assume the keyword this.

eg:

<script>
// function to cancel and return to account display page
function cancel_form(formName) {
alert(formName.name)
formName.submit();
}
</script>
</HEAD>

<BODY>
<form name="form1" action="mailto:">
<input type="button" name="submitIt" value="Cancel"
onclick="return cancel_form(this.form)">
</form>

<form name="form2" action="http://google.com">
<input type="button" name="submitIt" value="Cancel"
onclick="return cancel_form(form)">
</form>

.....Willy

Crashin
03-22-2004, 04:16 PM
Thank you both for your replies. They both work, and have given me a good piece of advice to use going down the road.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum