Petty_Crim Posted December 27, 2007 Share Posted December 27, 2007 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) } Quote Link to comment Share on other sites More sharing options...
wrong_move18 Posted December 27, 2007 Share Posted December 27, 2007 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> Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 28, 2007 Share Posted December 28, 2007 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 Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted December 28, 2007 Author Share Posted December 28, 2007 Its sort of working except when I push the button it refreshes the page and adds all the form data into the URL as GET variables. Is there a way to stop this? Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 28, 2007 Share Posted December 28, 2007 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 } Quote Link to comment Share on other sites More sharing options...
Petty_Crim Posted December 29, 2007 Author Share Posted December 29, 2007 Thx that did the trick Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.