Overwrite a function without using a namespace

  • Thread starter gimme_this_gimme_that
  • Start date
G

gimme_this_gimme_that

I have an anchor tag as follows:

<a href="javascript:copyValue(this,6);submitForm(this);">Click Here</
a>

In copyValue() I want to overwrite the submitForm() function when
action1 == 6.

I get an Identifier Expected Error.

I require a solution that doesn't put copyValue() and submitForm()
into a namespace.
(What I'm trying to do is overwrite submitFunction that is included in
a JS under the copyValue definition.)

Thanks.


<script language="JavaScript">
<!--

function copyValue(form, action1){
if (6 == action1 ) {
submitForm= function(this) {
var form = document.forms['idExpressForm'];
form.formType.value = 6;
form.submit();
}
}
}

function submitForm(theForm,action1){
var form = document.forms['idExpressForm'];
form.formType.value = action1;
form.submit();
}
//-->
 
G

gimme_this_gimme_that

Hi Randy,

You're sort of right.

copyValue can do anything that submitForm does - but submitForm always
gets called and I can't modify it. That's because of the why things
are getting called - from javascript in the anchor tag.

This is very close except this results in a Function expected error.
However, aside from the error, it successfully submits the form.



function copyValue(form, action1) {
if ( 6 == action1 ) {
submitForm=_submitForm();
} else {
var form = document.forms['idExpressForm'];
if ('object' == typeof form) {
if ('object' == typeof form.formType) {
form.formType.value = action1;
}
}
}
}



function _submitForm() {
var form = document.forms['idExpressForm'];
form.formType.value = 6;
form.submit();
return false;
}

function submitForm(theForm,action1){
var form = document.forms['idExpressForm'];
form.formType.value = action1;
form.submit();
}
 
H

Henry

On Feb 4, 9:25 pm, "(e-mail address removed)"
I get an Identifier Expected Error.
function copyValue(form, action1){
if (6 == action1 ) {
submitForm= function(this) {
<snip> ^^^^

The definition of a formal parameter to a function must consist of an
Identifier. You have used "this" above, and - this - is a keyword not
an Identifier. Thus your code is a syntax error, and the error message
is telling you exactly what is wrong in a surprisingly precise way.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top