Link to home
Start Free TrialLog in
Avatar of Natchiket
NatchiketFlag for United Kingdom of Great Britain and Northern Ireland

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 :(


Avatar of NicksonKoh
NicksonKoh
Flag of Singapore image

Hi Natchiket,

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
SOLUTION
Avatar of Roonaan
Roonaan
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Natchiket

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 ????

Thx for the grade! As a VB enthusiast, I dislike the javascript case sensitive too but now I say javascript is WOW!
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
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-
thanks roonan will try that ... stand by for my next 'challenging' question