View Full Version : Resolved cant pass values to Ajax function..

04-11-2011, 03:57 PM
I am using Ajax with PHP to authenticate id and pass at my site.
while the php script is working fine, the ajax is giving problems..
The comes to where hello is the id and world is the pass instead of loading the php script "idpass.php". I guess the values from the textbox are not being passed to Ajax function..

function showUser(str,str1)
if (str=='')
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if (xmlhttp.readyState==4 && xmlhttp.status==200)
xmlhttp.open("GET","idpass.php?q="+str +"&r="+str1,true);

<form onSubmit=showUser(this.value,this.value) >
<div id="txt"><b>Enter your username </b>
<input type="text" name= "username">
<b>Enter your password</b> <input type="password" name="pass">
<div id="txt1" style="display : none">help</div>
<input type="submit" value="Login" />

04-11-2011, 04:25 PM
Ok, I think you should consider a few things here

1) Put all attribute values into double quotes
2) on-handlers should be written in lower case
3) A form does not have a value ... so this.value in onsubmit is pointless
4) You should return false from your onsubmit handler, otherwise the page will be submitted and refreshed afterwards

Something like that:

<form onsubmit="showUser(); return false;">

In showUser() you can access the fields much easier if you give them id attributes like

<input type="text" name= "username" id="user">

Then you can get the value using