A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearstrange javascript form behaviour - page 1
User InfoPosts
strange javascript form behaviour#1
I am generating the following html form with this php:

echo "<form name=\"userForm\">
<input type=\"text\" name=\"username\" />
<br />
First name:
<input type=\"text\" name=\"firstname\" />
<br />
Last name:
<input type=\"text\" name=\"lastname\" />
<br />
<input name=\"Submit\" type=\"submit\" value=\"Update\" onclick=\"submitUserInfo();return false\"/>

Which is handled by submitUserInfo, which is here:

function submitUserInfo() {
url = "edit_user.php?cmd=submitinfo&username="+document.userForm.username.value+"&firstname="+document.userForm.firstname.value+"&lastname="+document.userForm.lastname.value;
var xmlHttp=GetXmlHttpObject();
if(xmlHttp.responseText == (true() {

I clearly have url defined as beginning with


however when pressing the submit button, it tries to send the url as


and I cannot figure out why. I have used the above technique succusfully with other forms on my site, and can not find any reason that cmd=submitinfo& is being excluded.

posted date: 2009-04-08 12:03:00

Re: strange javascript form behaviour#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-08 12:03:01

Re: strange javascript form behaviour#3
Use a tool like Firebug to determine if the browser is sending it without cmd=submitinfo& or if it(s being lost on the server side.

posted date: 2009-04-08 12:09:00

Re: strange javascript form behaviour#4
Change:url = "edit_user.php?cmd=submitinfo&username="+document.userForm.username.value+"&firstname="+document.userForm.firstname.value+"&lastname="+document.userForm.lastname.value;to:var url = "edit_user.php?cmd=submitinfo&username="+document.userForm.username.value+"&firstname="+document.userForm.firstname.value+"&lastname="+document.userForm.lastname.value;You must declare your url variable before you try to use it.Also, avoid echoing straight HTML to the page. The way you(ve done it is going to be an absolute pain to debug, update, and stylize.

posted date: 2009-04-08 12:20:00

Re: strange javascript form behaviour#5
What's the GetXmlHttpObject implementation ? What's that check on responseText == 'true' ? What happens if you try to make url local (var url = "...";) ? What happens if you display the url just after you build it ? what happens if you display it just after the call to GetXmlHttpObject ?

posted date: 2009-04-08 12:21:00

Re: strange javascript form behaviour#6
Wouldn't displaying the url be just as useful to see if I am sending it clientside or not?

posted date: 2009-04-08 12:24:00

Re: strange javascript form behaviour#7
Frameworks like jQuery is not really needed for such simple tasks, although I would suggest you taking a look if you plan to implement more JavaScript on your site.Your code, using jQuery, would look like this:$("#<id of form goes here>").submit(function (){ $.ajax({ data: { "username": $("#<id of username-input goes here>").val(), "firstname": $("#<id of firstname-input goes here>").val(), "lastname": $("#<id of lastname-input goes here>").val() }, url: "edit_user.php" }); return false;});Looks a bit nicer, I think :)Also; using frameworks - not jQuery in particular - takes care of browser work-arounds.. so you won(t have to.. take care of (em, that is :)

posted date: 2009-04-08 12:35:00

Re: strange javascript form behaviour#8
I think you need to change the type of the button from "submit" to "button":<input name=\"Submit\" type=\"button\" value=\"Update\" onclick=\"submitUserInfo();return false\"/>

posted date: 2009-04-08 12:59:00

select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.