Reputation: 3439
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 :)
Upvotes: 0
Views: 101
Reputation: 10727
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()">
Upvotes: 2
Reputation: 994
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()">
Upvotes: 0