Results 1 to 8 of 8

Thread: Form help ajax

  1. #1
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Form help ajax

    I made form but i need when i submit show thanks without having refresh or reload the page. Anyone plz help me

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Code:
    var url = "contact.php";
    
    var ajaxObject = false;
    
    if (window.XMLHttpRequest) {
    ajaxObject = new XMLHttpRequest();
    } 
    
    else if (window.ActiveXObject) {
    ajaxObject = new ActiveXObject("Microsoft.XMLHttp");
    }
    
    
    if (ajaxObject) {
    var obj = document.getElementById("divName");
    ajaxObject.open("GET", url);
    
    ajaxObject.onreadystatechange = function()
    {
    if (ajaxObject.readyState == 4 &&
    ajaxObject.status == 200) {
    
    obj.innerHTML = ajaxObject.responseText;
    }
    }
    ajaxObject.send(null);
    }
    Not sure if this is what you're looking for, but hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I have no idea how to do this...I attach it plz make it for me and others pplz too who needs this

  4. #4
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hello ???

  5. #5
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    I started to work on it, but there were a ton of errors. I don't know that much about AJAX, but I know some of the other members of the forums know about it.
    Sorry I can't help any further, but perhaps someone else can.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  6. #6
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    same here..i also dont know abt ajax thats y i asking u

    anyways

    wait for any one else

  7. #7
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    contact.htm

    HTML Code:
    							<!-- Contact -->
    <script type="text/javascript">
    /*
    Required for Ajax
    DO NOT REMOVE
    */
    function makeRequest(url, eId, getpost, senddata) {
    	if(getpost == "undefined" || getpost != "POST" || getpost != "GET") {
    		getpost = "GET";
    	} 
    	var http_request = false;
    		if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    			http_request = new XMLHttpRequest();
    				if (http_request.overrideMimeType) {
    					http_request.overrideMimeType('text/xml');
    					// See note below about this line
    				}
    		} else if (window.ActiveXObject) { // IE
    			try {
    				http_request = new ActiveXObject("Msxml2.XMLHTTP");
    			} catch (e) {
    				try {
    					http_request = new ActiveXObject("Microsoft.XMLHTTP");
    				} catch (e) {}
    			}
    		}
    
    	if (!http_request) {
    		alert('Giving up :( Cannot create an XMLHTTP instance');
    		return false;
    	}
    	
    	http_request.onreadystatechange = function() {
    		if (http_request.readyState == 4 && http_request.status == 200)	{
    			
    			document.getElementById(eId).innerHTML = http_request.responseText;
    		}
    		else	{
    			document.getElementById(eId).innerHTML = "Please wait..."
    		}
    	};
    	http_request.open(getpost, url, true);
    	if(getpost == "POST") {
    		http_request.send(senddata);
    	} else {
    		http_request.send(null);
    	}
    }
    function send()	{
    
    	var form = document.forms['contact']
    	var email = form.elements['EmailFrom'].value
    	var name = form.elements['Name'].value
    	var subject = form.elements['Subject'].value
    	var message = form.elements['Message'].value
    	var get = "?EmailFrom="+email+"&Name="+name+"&Subject="+subject+"&Message="+escape(message)
    	var url = "contact.php" + get
    	makeRequest(url,'contactarea')
    }
    </script>							
    							<div id="contactarea">
    <form method="GET" action="contact.php" onSubmit="send();return false" name="contact">
    <p>Email From:<br>
    <input type="text" name="EmailFrom">
    <p>Name:<br>
    <input type="text" name="Name">
    <p>Subject:<br>
    <select name="Subject">
      <option value="Suggestion" selected>Suggestion</option>
      <option value="Report">Report</option>
      <option value="Request">Request</option>
    </select>
    <p>Message:<br>
    <textarea rows="8" name="Message" cols="34"></textarea>
    <p><input type="submit" name="submit" value="Submit">
    </form>
    <p>
    </div>
    <!-- End Contact -->
    contact.php

    PHP Code:
    <?php


    // get posted data into local variables
    $EmailFrom trim(stripslashes($_GET['EmailFrom'])); 
    $EmailTo "XX@XX";
    $Subject "Contact: $Subject";
    $Name trim(stripslashes($_GET['Name'])); 
    $Subject trim(stripslashes($_GET['Subject'])); 
    $Message trim(stripslashes($_GET['Message'])); 

    // validation
    $validationOK=true;
    if (
    trim($EmailFrom)==""$validationOK=false;
    if (
    trim($Name)==""$validationOK=false;
    if (!
    $validationOK) {
      print 
    "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
      exit;
    }

    // prepare email body text
    $Body "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Subject: ";
    $Body .= $Subject;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";

    // send email 
    $success mail($EmailTo$Subject$Body"From: <$EmailFrom>");

    print 
    "Thanks, $Name";
    ?>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  8. #8
    Join Date
    Jan 2007
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks !!

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
  •