468,771 Members | 1,810 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,771 developers. It's quick & easy.

onclick doesn't work

Hi,

I've this piece of code which does not work at all.
Can anyone point out my mistake?

I've 2 buttons. History button will call verifyFields() function and
lead to
different page for processing. verifyFields() is working fine and so
does the
history() function.

But,

the other save button doesn't work. It's supposed to call the save()
function and before executing the action, it will perform a check by
executing
checkFormFields(). However it does not execute these statements:
--------------------------------------------------------------------
document.ListForm.target="origin";
document.ListForm.action="ListByOrigin_updaterecor d.asp?action=check";
--------------------------------------------------------------------
The links above have been verified and it's working.


<SCRIPT LANGUAGE="JavaScript">
<!--

function checkFormFields()
{
if(!isNumber(ListForm.destination.value))
{
alert("Destination must not contain numbers at all.");
ListForm.destination.focus();
return false;
}
return true;
}

function history()
{
document.ListForm.target="adhoc";
document.ListForm.action="ListByOrigin.asp?action= check";
}

function save()
{
if (checkFormFields() ) //doesn't execute these 2 lines.
{
document.ListForm.target="origin";
document.ListForm.action="ListByOrigin_updaterecor d.asp?action=check";
return true;
}
}
//-->
</script>
<form action="" method="post" name="ListForm" onSubmit="return
verifyFields();">

<input name="submit" type="submit" value="History"
onClick="history()">

<input name="submit" type="submit" id="submit" value="Save"
onClick="return save();">

</form>
Jul 23 '05 #1
2 2167
kelvin wrote:
Hi,

I've this piece of code which does not work at all.
Can anyone point out my mistake?

I've 2 buttons. History button will call verifyFields() function and
lead to
different page for processing. verifyFields() is working fine and so
does the
history() function.

But,

the other save button doesn't work. It's supposed to call the save()
function and before executing the action, it will perform a check by
executing
checkFormFields(). However it does not execute these statements:
--------------------------------------------------------------------
document.ListForm.target="origin";
document.ListForm.action="ListByOrigin_updaterecor d.asp?action=check";
--------------------------------------------------------------------
The links above have been verified and it's working.

<SCRIPT LANGUAGE="JavaScript">
<script type="text/javascript">
<!--
<!-- Not needed.
function checkFormFields()
{
if(!isNumber(ListForm.destination.value))
Where is "isNumber()" defined? It's not in the source you provided. As a result any
attempt to call isNumber() will result in a syntax error.
{
alert("Destination must not contain numbers at all.");
ListForm.destination.focus();
return false;
}
return true;
}

function history()
{
document.ListForm.target="adhoc";
document.ListForm.action="ListByOrigin.asp?action= check";
}

function save()
{
if (checkFormFields() ) //doesn't execute these 2 lines.
As indicated above, checkFormFields() contains a call to an undefined function.
{
document.ListForm.target="origin";
document.ListForm.action="ListByOrigin_updaterecor d.asp?action=check";
return true;
}
You use "return save()" on the form, but save() does not always return a value, you should
add "return false;" here. It may work without it, but it's a good habit to have functions
that are supposed to return something always explicitly return something.
}
//-->
//--> Not needed
</script>

<form action="" method="post" name="ListForm" onSubmit="return
verifyFields();">

<input name="submit" type="submit" value="History"
onClick="history()">

<input name="submit" type="submit" id="submit" value="Save"
onClick="return save();">

</form>


--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
* http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
* http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 23 '05 #2
hi Grant,

I've done some changes and it works now.
Thank you for your advise.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by Erik | last post: by
3 posts views Thread by Jamie Jackson | last post: by
10 posts views Thread by Noozer | last post: by
10 posts views Thread by Eric-Sebastien Lachance | last post: by
13 posts views Thread by pagates | last post: by
11 posts views Thread by Daz | last post: by
3 posts views Thread by Michael_R_Banks | last post: by
20 posts views Thread by Charles | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Marin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.