Malak Malak - 1 month ago 13
HTML Question

onClick() function can't trigger javascript code

I have a small problem. I tried to add an

onClick
function to my submit button but my JavaScript doesn't run. I dont't know where the error is :(
When I put the code inside
onClick
property the alert dialog works fine.

<head>
<script type="text/javascript">
fuction login() {
alert('hello');
}
</script>
</head>

<body>
<form action="javascript:void(0);" method="">
<fieldset class="clearfix">
<p><span class="fontawesome-user"></span><input type="text" value="إسم المستخدم أو الأيميل" name="username" onBlur="if(this.value == '') this.value = 'إسم المستخدم أو الأيميل'" onFocus="if(this.value == 'إسم المستخدم أو الأيميل') this.value = ''" required/></p>
<!-- JS because of IE support; better: placeholder="Username" -->

<p><span class="fontawesome-lock"></span><input type="password" value="كلمة السر" name="psw" onBlur="if(this.value == '') this.value = 'كلمة السر'" onFocus="if(this.value == 'كلمة السر') this.value = ''" required/> </p>
<!-- JS because of IE support; better: placeholder="Password" -->

<p><input type="submit" value="Login" onClick="login();" /></p>
</fieldset>
</form>
</body>

Answer

I see you have made a simple spelling of "function" above.

Please change it into function login(){...