SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Threaded View

  1. #1
    SitePoint Zealot
    Join Date
    Jun 2007
    Location
    Regina, SK, Canada
    Posts
    129
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple Ajax Question

    I have a code that works perfectly fine when I have this <a onclick="checkDate(ver)">Check it</a>. It will alert "ok" and "not ok" But as soon as I apply it to a <form> tag, it doesnt use the return statements I'm making. It just alerts "not ok" every time. I would like it to not submit if the function returns false.

    For the HTML I have

    Code HTML4Strict:
    <form onsubmit="return checkDate('1')" method="post">

    And for the AJAX I have...

    Code JavaScript:
    var xmlHttp
     
    function checkDate(ver)
    { 
    	xmlHttp=GetXmlHttpObject()
    	if (xmlHttp==null)
    	{
    		alert ("Browser does not support HTTP Request")
    	} 
     
    	var year = document.getElementById('year').value;
    	var month = document.getElementById('month').value;
    	var date = document.getElementById('date').value;
    	var url="ajax-checkdate.php"
    	url=url+"?date="+year+'-'+month+'-'+date;
    	xmlHttp.onreadystatechange=function(){stateChanged(ver)}	
    	xmlHttp.open("GET",url,true)
    	xmlHttp.send(null)
    }
     
    function stateChanged(ver)
    { 
     if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
    	var checkit = xmlHttp.responseText;
    		if(checkit != 'ok'){
    			alert('not ok');
    			return false;
    		} else {
    			alert('ok');
    			return true;
    		}
    	} 
    }

    Hopefully a Java knight in shining armor will be able to help me
    Last edited by jboesch; Jul 27, 2007 at 12:09.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •