Jump to content

[SOLVED] Sending Form Data to a JS Function


Petty_Crim

Recommended Posts

I'm making a small ajax thing and am stuck with trying to send form data to an java script function. At the  moment when i click the submit button it doesn't do anything except stick the form stuff into get variables in the url.

 

This is my php form:

<form name='member_add' onsubmit='showUser(member_add.member_list.value, member_add.category_list.value, member_add.description.value);'>

<input type='text' name='member_list'>

<input type='text' name='category_list'>

<input type='text' name='description'>

</form>

 

This is my js function

function showUser(member category, description)

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

alert ("hello")

var url="getuser.php"

url=url+"?member="+member

url=url+"?category="+category

url=url+"?description="+description

 

xmlHttp.onreadystatechange=stateChanged

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

 

Link to comment
Share on other sites

This is my php form:

<form name='member_add' onsubmit='showUser(member_add.member_list.value, member_add.category_list.value, member_add.description.value);'>

<input type='text' name='member_list'>

<input type='text' name='category_list'>

<input type='text' name='description'>

</form>

 

You can use this...

<form name='member_add' onsubmit='showUser(this.member_list.value, this.category_list.value, this.description.value);'>
<input type='text' name='member_list'>
<input type='text' name='category_list'>
<input type='text' name='description'>
</form>

 

or if it doesn't work, use this..

 

<form name='member_add' onsubmit='showUser(document.forms["member_add"].member_list.value, document.forms["member_add"].category_list.value, document.forms["member_add"].description.value);'>
<input type='text' name='member_list'>
<input type='text' name='category_list'>
<input type='text' name='description'>
</form>

Link to comment
Share on other sites

var url="getuser.php"
url=url+"?member="+member
url=url+"?category="+category
url=url+"?description="+description

only the second line above should have a '?'. instead the 3rd and forth should have a '&'

var url="getuser.php"
url=url+"?member="+member
url=url+"&category="+category
url=url+"&description="+description

 

Link to comment
Share on other sites

you must 'return false' from your 'showUser()' routine so that the default action of the form does not take place(form submittal).

function showUser(member category, description)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return true; //submit normal way
}
alert ("hello")
var url="getuser.php"
url=url+"?member="+member
url=url+"?category="+category
url=url+"?description="+description

xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
return false; // stop normal form submital
}

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.