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
Kishan Bheemajiyani
3,4396 gold badges39 silver badges74 bronze badges
2 Answers 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
user987339
10.7k8 gold badges45 silver badges48 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Kishan Bheemajiyani
Java script getting executed. there is not doubt of that because simple function getting executed.
user987339
And add on click event.
user987339
You have to put it this way : <script type="text/javascript" src="jsfiles/JsScript.js"></script> in order to load js file.
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
Jose Luis
9941 gold badge8 silver badges22 bronze badges
4 Comments
Kishan Bheemajiyani
<td>Email *: <input type="text" name="email" id="email" onfocus="checkmail()" /></td>
Jose Luis
Better onfocusout. :-)
Kishan Bheemajiyani
Its working if i include in that Jsp only internal. But trying to include it external and its not working :(
Jose Luis
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. :-)
lang-js
preventDefault, orevent.stopPropagation()