I have jquery, implementing AJAX and trying to validate the input in form, but I got into error. I think, it is due to having too much javascript, I don't know. I don't know much about Javascript.
Here is my code:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Main page</title>
Javascript Code:
Original
- Javascript Code |
|
|
|
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script src="http://code.jquery.com/ui/1.9.1/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#accordion" ).accordion();
});
</script>
<?php
include('includes/header.inc');
include('includes/leftColumn.inc');
?>
</head>
<body>
<form>
...
........
............
Javascript Code:
Original
- Javascript Code |
|
|
|
<script>
/************************************
*Below is the script for AJAX:
**********************************/
function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","gethint.php?q="+str,true);
xmlhttp.send();
}
</script>
Topping:
<p><b>Start typing a topping name in the input field below:</b></p>
<input type="text" onkeyup="showHint(this.value)">
<p>Suggestions: <span id="txtHint"></span></p>
</p>
</div>
.........
........
Javascript Code:
Original
- Javascript Code |
|
|
|
<script>
/**************************
*Validation script:
*************************/
function validateForm()
{
var x=document.forms["myForm"]["fName"].value;
if (x==null || x=="")
{
alert("First name must be filled out");
return false;
}
{
var x=document.forms["myForm"]["lName"].value;
if (x==null || x=="")
{
alert("Last name must be filled out");
return false;
}
}
</script>
<input type="submit" value="Submit Order" onsubmit="return validateForm()" />
</form>
........
...........
But javascript validator is not working. it passess somehow. can't solve this problem.
Any suggestion?