Natchiket
asked on
tying onclick event to a java function
Hi experts, this should be an easy one
All I'm trying to do is run a function when someone clicks on a button, and I don't want to have to embed the function in the INPUT tab
<HTML>
<BODY>
<HEAD>
<SCRIPT language="Javascript">
Function cmdSearch_Click()
{
Alert("I was clicked")
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Search Facility</H1>
<HR>
<FORM Name="frmSearch">
Enter the Surename:
<INPUT TYPE="Text" Name="txtName" Size=10><INPUT Type="Button" Name="cmdSearch" VALUE="Search">
</FORM>
</BODY>
</HTML>
So when I click on cmdSearch nothing happens
if I change the INPUT tag thus
<INPUT Type="Button" Name="cmdSearch" VALUE="Search" onclick=cmdSearch_Click()>
I get Error on page :(
All I'm trying to do is run a function when someone clicks on a button, and I don't want to have to embed the function in the INPUT tab
<HTML>
<BODY>
<HEAD>
<SCRIPT language="Javascript">
Function cmdSearch_Click()
{
Alert("I was clicked")
}
</SCRIPT>
</HEAD>
<BODY>
<H1>Search Facility</H1>
<HR>
<FORM Name="frmSearch">
Enter the Surename:
<INPUT TYPE="Text" Name="txtName" Size=10><INPUT Type="Button" Name="cmdSearch" VALUE="Search">
</FORM>
</BODY>
</HTML>
So when I click on cmdSearch nothing happens
if I change the INPUT tag thus
<INPUT Type="Button" Name="cmdSearch" VALUE="Search" onclick=cmdSearch_Click()>
I get Error on page :(
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ha ha ha ok alert rather than Alert
that's my VBA background
Thanks for the advice folks
what's out of date about my html ????
that's my VBA background
Thanks for the advice folks
what's out of date about my html ????
Thx for the grade! As a VB enthusiast, I dislike the javascript case sensitive too but now I say javascript is WOW!
ASKER
yes I tend to agree (even though it's only my second day of using it)
alhough the only reason i'm using it is because when I asked a vbscript question on EE, the only respnse I got was in JS
alhough the only reason i'm using it is because when I asked a vbscript question on EE, the only respnse I got was in JS
Try validating your html using validator.w3.org and you'll know what I mean with old html.
Tags shouldn't be in uppercase, attribute values should be within quotes. <script language> should by <script type, input tags should have a closing <input /> etc.
-r-
Tags shouldn't be in uppercase, attribute values should be within quotes. <script language> should by <script type, input tags should have a closing <input /> etc.
-r-
ASKER
thanks roonan will try that ... stand by for my next 'challenging' question
Function cmdSearch_Click()
should be
function cmdSearch_Click()
and change
<INPUT Type="Button" Name="cmdSearch" VALUE="Search" onclick=cmdSearch_Click()>
to
<INPUT Type="Button" Name="cmdSearch" VALUE="Search" onclick="cmdSearch_Click()
Cheers
Nickson