Jump to content

var name = document.getElementById('name');


farkewie

Recommended Posts

Hello,

new to Javascipt, i hace downloaded the yahoo ajax tools and i am trying to get some post requests working without loading the page,

 

i have tried to add some code so it sends a username and password from text fields but its not working here is what i get when i do print_r($_POST)

 

 

Array (

 

[name] => [object]

[pass] => [object]

 

)

 

and here is my code - this is just testing once i get this working ill start coding allthe page properly.

 


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<meta name="author" content="fuckme">
<script src="js/yahoo.js"></script>
<script src="js/event.js"></script>
<script src="js/connection.js"></script>
<title>Untitled 9</title>
</head>

<body>
<form name="form1" method="post" action="" id="form1">
<table width="204">
<tr><td>name</td><td>pass</td>
</tr>
    <tr>
      <td><label>
        <input type="text" name="name" id="name">
      </label></td>
      <td><label>
        <input type="text" name="pass" id="pass">
      </label></td>
    </tr>
  </table>
  <label>
<input type="button" name="button" id="button" value="Submit" onClick="makeRequest();" >
  </label>
</form>


<div id="container"></div>

<script>
var div = document.getElementById('container');

var handleSuccess = function(o){
YAHOO.log("The success handler was called.  tId: " + o.tId + ".", "info", "example");
if(o.responseText !== undefined){
	div.innerHTML +=  o.responseText;

}
};

var handleFailure = function(o){
	YAHOO.log("The failure handler was called.  tId: " + o.tId + ".", "info", "example");

if(o.responseText !== undefined){
	div.innerHTML = "<li>Transaction id: " + o.tId + "</li>";
	div.innerHTML += "<li>HTTP status: " + o.status + "</li>";
	div.innerHTML += "<li>Status code message: " + o.statusText + "</li>";
}
};

var callback =
{
  success:handleSuccess,
  failure:handleFailure,
  argument:['foo','bar']
};
var name = document.getElementById('name');
var pass = document.getElementById('pass');
YAHOO.util.Connect.setForm(form1); 
var sUrl = "post.php";
var postData = "name=" + name +"&pass=" + pass +"";

function makeRequest(){

var request = YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, postData);

YAHOO.log("Initiating request; tId: " + request.tId + ".", "info", "example");

}

YAHOO.log("As you interact with this example, relevant steps in the process will be logged here.", "info", "example");
</script>





</body>
</html>

 

Thank you

Link to comment
Share on other sites

here's a good ajax form tutorial - take a look at it and go from there:

 

http://www.tizag.com/ajaxTutorial/ajaxform.php

 

I did notice your not including your post url in you ajax function - I think it should be like this:

 

<input type="button" name="button" id="button" value="Submit" onClick="makeRequest('process-login.php');" >

 

also ajax questions belong on this forum:

 

http://www.phpfreaks.com/forums/index.php/board,51.0.html

 

this forum is just for JavaScript -  Good Luck. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.