First you had this code, and do note the call "myFunc()"
varai;10961282 wrote:
<form action="" method="post">
<input type="text" maxlength="30" />
[COLOR="Red"]<a href="javascript:void(0);" onclick="myFunc()">add new credit card</a>[/COLOR]</form>
Then, in your next post, you provide an argument when you call the function, i.e. this.form, in the call to myFunc.
varai;10961405 wrote:
<form name="myForm" action="" method="post">
<input type="text" maxlength="30" />
<a href="[COLOR="red"]javascript:void(0)[/COLOR];" onclick="myFunc(this.form);">add new credit card</a>
</form>
varai;10961405 wrote:
<script language="javascript" type="text/javascript">
function myFunc(which)
{[COLOR="Red"]which.action="index.html";[/COLOR]
which.submit();
return true;
}
</script>
error: which is undefined. Then the debugger jumps to javascript:void(0) and nothing happens after that.
Now, looking at this last part, you can start by dropping language="javascript", since there is no such thing. Iirc, the script element doens't have a language attribute, and if it did, it would be a natural language, such as "en" or "en-us".
Looking at the function definition, there is one function argument called which.
which will be whatever you pass along to the function when you call it. If you provide no argument, or provide the argument "undefined" (without quotes), I'd exepct the error message you get.
You write something like "goes on to call javascript:void(0)", but that actually happens at the same time as your onclick event fires.
When you click a link, the href attribute is used; to load a new document, to jump to a document fragment (#id), or to run javascript (javascript:...). However, the things that take place due to the href attribute is not an event, and as such there will be no event object. javascript:void(0) does nothing (more or less), which means that no new document will be loaded and the browser will not scroll in the current document to some other point, thus allowing your onclick to be run without other side effects. In other words, your error has nothing to do with the href attribute.
But since you are not using the event object in your event handler function, you could just as well use
<a href="javascript:myFunc(...);">...</a>
But the first thing I'd add to myFunc is alert(which) to see what you are really passing along.
And considering that there is no form property listed for elements at this page, this.form might be the reason your script fails (i.e. it is undefined).