-2

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>
jcuenod
  • 55,835
  • 14
  • 65
  • 102
Malak
  • 19
  • 4
  • Check your console for any errors. – mehulmpt Nov 05 '16 at 21:11
  • It says fuction and not function in your code – thsorens Nov 05 '16 at 21:13
  • Downvoting because you posted before checking the console for obvious syntax errors. – Barmar Nov 05 '16 at 21:16
  • @Malak I have cleaned up your question a bit. Please take note of how much of your code I chopped out. I removed lots of things that you should have been able to see did not affect this question but clog it up for anyone who wants to try to help you (and makes it more likely people will reach for the downvote button). – jcuenod Nov 05 '16 at 21:23
  • @jcuenod thanx 4 your help – Malak Nov 05 '16 at 21:31

2 Answers2

1

Problem: You have misspelled function in your script at the top:

<script type="text/javascript">
  function login() {            // this line is where the change is
    alert('hello');
  }
</script>

Recommendation: This is why using a code editor really helps. A syntax highlighter will show that fuction is not a recognised word and it will appear in a different colour. Take a look at atom for an excellent free one.

jcuenod
  • 55,835
  • 14
  • 65
  • 102
1

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

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

HENOK MILLION
  • 309
  • 1
  • 9