0

I have created one simple demo where external java script getting called. but its not getting called on onclick function please advice.

here example.

<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<script type="text/javascript"
 src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="\\jsfiles\\JsScript.js"></script>
<title>Insert title here</title>
</head>
<body>
 <h1>Project is working fine</h1>
 <form action="HelloWorld" method="get">
 <table border="2">
 <tr>
 <td>Username *: <input type="text" name="username"
 id="username" /></td>
 </tr>
 <tr>
 <td>Password *: <input type="password" name="pwd" id="password" /></td>
 </tr>
 <tr>
 <td>Surname *: <input type="text" name="surname" /></td>
 </tr>
 <tr>
 <td>Other Names *: <input type="text" name="names" /></td>
 </tr>
 <tr>
 <td>Date of Birth *: <input type="text" name="dob" /></td>
 </tr>
 <tr>
 <td>Email *: <input type="text" name="email" id="email"
 onclick="checkmail()" /></td>
 </tr>
 <tr>
 <td>Telephone: <input type="text" name="tel" /></td>
 </tr>
 <tr>
 <td>Address *: <input type="text" name="add" /></td>
 </tr>
 <tr>
 <td>Post Code *: <input type="text" name="ptc" /></td>
 </tr>
 <tr>
 <td><input type="submit" value="Submit" onchange="checkmail()"></td>
 </tr>
 </table>
 </form>

And Js file is.

function checkmail() {
 alert("Callled");
 alert(document.getElementById("email"));
}

Appreciate your answers in advance :)

georg
216k57 gold badges325 silver badges401 bronze badges
asked Apr 8, 2016 at 8:04
3
  • use preventDefault, or event.stopPropagation() Commented Apr 8, 2016 at 8:05
  • can u explain that ? Commented Apr 8, 2016 at 8:07
  • Have you checked the console to see if there are any errors? Also, it might be worth checking the network tab (or similar for your browser) to ensure the file is being pulled into the browser. Commented Apr 8, 2016 at 8:11

2 Answers 2

2

This line is wrong:

<script type="text/javascript" src="\\jsfiles\\JsScript.js"></script>

Change it to

<script type="text/javascript" src="jsfiles/JsScript.js"></script>

And add onclick event:

 <input type="submit" value="Submit" onclick="checkmail()">
answered Apr 8, 2016 at 8:06
Sign up to request clarification or add additional context in comments.

3 Comments

Java script getting executed. there is not doubt of that because simple function getting executed.
And add on click event.
You have to put it this way : <script type="text/javascript" src="jsfiles/JsScript.js"></script> in order to load js file.
0

You are using an 'onchange' envent with a button:

 <input type="submit" value="Submit" onchange="checkmail()">

It should be onclick:

 <input type="submit" value="Submit" onclick="checkmail()">
answered Apr 8, 2016 at 8:07

4 Comments

<td>Email *: <input type="text" name="email" id="email" onfocus="checkmail()" /></td>
Better onfocusout. :-)
Its working if i include in that Jsp only internal. But trying to include it external and its not working :(
This is a path problem, you have to write the correct path from the jsp file to the js file. You could ask a new question, if you have doubts. :-)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.