help me sir
Posted: Mon Jun 27, 2016 6:47 am
Hello sir,
I have wrote form validation code in javascript, it is working fine on register.php
In index.php I loaded register.php in a div through ajax. When I am trying to submit empty form then form validation code does not work. And register.php disappear from container div.
I would like to say when I submit empty form that do not disappear from container div till I fill a value and click on submit button.
My program code is written bellow. If anybody help me then I will be great full of him/her.
Register.php
Index.php
I have wrote form validation code in javascript, it is working fine on register.php
In index.php I loaded register.php in a div through ajax. When I am trying to submit empty form then form validation code does not work. And register.php disappear from container div.
I would like to say when I submit empty form that do not disappear from container div till I fill a value and click on submit button.
My program code is written bellow. If anybody help me then I will be great full of him/her.
Register.php
Code: Select all
<?php
$page=$_SERVER['SCRIPT_NAME'];
if(isset($_POST['username']) && !empty($_POST['username'])){
echo 'OK';
}
?>
<script type="text/javascript">
function check(){
if(document.getElementById('username').value == ""){
document.getElementById('username').style.borderColor="red";
return false;
}
}
</script>
<form action="<?php echo $page;?>" method="POST" onsubmit="return check();">
Your name: <input type="text" id="username" name="username" />
<input type="submit" />
</form>Code: Select all
<script type="text/javascript">
function load(){
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
else{
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
}
xmlHttp.onreadystatechange= function(){
if(xmlHttp.readyState == 4 && xmlHttp.status == 200){
document.getElementById('container').innerHTML=xmlHttp.responseText;
}
}
xmlHttp.open('GET','register.php' ,true);
xmlHttp.send(); }
</script>
<a href="#" onclick="load();" >register</a>
<br />
<div id="container"></div>
<style>
#container{
width: 350px;
padding: 40px;
background-color: beige;
}
</style>