CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   return false; not working... (http://www.codingforums.com/showthread.php?t=187440)

SiM99_wrk 01-22-2010 01:33 PM

return false; not working...
 
Hi all,

I have a page built with asp.net that includes some "imagebutton"s within a form. These render as input tags with the type set to image. I ahve the onclick attribute set to run a custom javascript function and return false, so in the fully rendered page I get something like the following:

Code:

<input type="image" name="ctl00${cut}" tabindex="-1" title="Click to look up the details" src="images/load_details.png" onclick="LoadDetails(); return false;" style="border-width:0px;" />
This has worked fine for the few months the code has been in place and then just recently (within the last few days) it has stopped working for a single network user. They click on the link and instead of the function executing (and the AJAX loading details into the page) the form submits. This makes me think that the "return false" simply isn't executing. The user says that they haven't changed any settings or anything that may cause this issue...

The browser being used throughout the company is IE8 under Windows XP. I have checked the version being used on their comptuer and it is 8.0.6001.18702, which is the same version as the one installed on my local machine... which is working fine. Another user has logged into the computer being used by the user with the issues and it works fine for the second user. Also, the user having the issues has logged into a different computer on the network and was still having the same problems.

I think I've included all the details, but I'll happily provide any required information.

Anyone have any ideas? :)

tomws 01-22-2010 02:13 PM

Have you already confirmed this user has Javascript enabled? You can either look through the IE settings or push a noscript tag into the page.

abduraooft 01-22-2010 02:22 PM

Quote:

This has worked fine for the few months the code has been in place and then just recently (within the last few days) it has stopped working for a single network user. They click on the link and instead of the function executing (and the AJAX loading details into the page) the form submits.
An error in the javascript might be the cause. Make use of firebug in FF to track it.

Kor 01-22-2010 02:46 PM

return false will stop the execution of the event which calls it. As long as you call it onclick, the event stopped will be onclick, not onsubmit. The submit action belongs to other element: the FORM element, thus I think your code should look like:
Code:

<form action="" onsubmit="return LoadDetails()">

SiM99_wrk 01-22-2010 02:49 PM

Quote:

Originally Posted by tomws (Post 913750)
Have you already confirmed this user has Javascript enabled? You can either look through the IE settings or push a noscript tag into the page.

Yes, javascript is definitely enabled. I did miss out a couple of details before though;
- there are multiple javascript based buttons on the same page.
- certain javascript based links/image buttons in the page work fine.
- I added the url (http://intranet_address) to trusted sites and changed the trusted site security level to "low"

The links that seem to work fine are the ones that require the page to be submitted, e.g. there's a "cancel" link that simply takes the user back to the main listing (the page with the issues is used for data editing). This renders as:
Code:

<a id="{id}" href="javascript:__doPostBack('{id}','')">Cancel</a>
(where {id} used to be a .net generated control id)

This is why I titled the post "return false; not working" - because javascript is working fine, it's just the "return false;" part that doesn't seem to do anything...

SiM99_wrk 01-22-2010 03:01 PM

Quote:

Originally Posted by abduraooft (Post 913755)
An error in the javascript might be the cause. Make use of firebug in FF to track it.

Good idea, I'll see what the sys admin says about me installing software on someone elses computer ;)

Quote:

Originally Posted by Kor (Post 913765)
return false will stop the execution of the event which calls it. As long as you call it onclick, the event stopped will be onclick, not onsubmit. The submit action belongs to other element: the FORM element, thus I think your code should look like:
Code:

<form action="" onsubmit="return LoadDetails()">

I don't want the image to submit the form, that's the point.

The image button is suposed to be using AJAX to load details from a remote server. Another image button in the same form is supposed to make the name entered into a textbox "Proper Case". (and there's a number of other buttons used to process things client side) The whole form is being used to add/edit a record in the database... obviously, moving the javascript to the onsubmit event wouldn't work in this case.

Kor 01-22-2010 03:09 PM

Quote:

Originally Posted by SiM99_wrk (Post 913771)
I don't want the image to submit the form, that's the point.

Then why do you use an image input? Why do you need a form, if you don't want to submit data?

Once again, the submit action can be stopped only within the FORM element while using return false the the onsubmit event.
Code:

<form action="" onsubmit="return false">

SiM99_wrk 01-22-2010 03:34 PM

Quote:

Originally Posted by Kor (Post 913775)
Then why do you use an image input? Why do you need a form, if you don't want to submit data?

Because the page is written in ASP.net and an image input is what si rendered from using an imagebutton.... and I DO want to "submit data", just not from this button.

Kor 01-22-2010 03:35 PM

Quote:

Originally Posted by SiM99_wrk (Post 913787)
and I DO want to "submit data", just not from this button.

For the last time: "the submit action can be stopped only within the FORM element while using return false the the onsubmit event"

What is not clear? Do you have other submit/image inputs within the same form?

SiM99_wrk 01-25-2010 10:02 AM

Quote:

Originally Posted by Kor (Post 913788)
For the last time: "the submit action can be stopped only within the FORM element while using return false the the onsubmit event"

Okay.
Does that mean that you're telling me that the other 99.9% of computers making use of the page, where clicking this button doesn't submit the form because I have "return false;" in the onclick event are behaving incorrectly? That the correct behaviour would in fact be to allow the form to submit instead?

Quote:

Originally Posted by Kor (Post 913788)
Do you have other submit/image inputs within the same form?

Quote:

Originally Posted by SiM99_wrk (Post 913725)
I have a page built with asp.net that includes some "imagebutton"s within a form.

Yes, there is more than one image button in use.


Further to the information provided so far, this only seems to happen under the single user's profile. Someone else logging into the same computer was able to use the pages correctly and the user logging into a different computer didn't help - the image button still submitted the page.

Kor 01-25-2010 12:43 PM

Quote:

Originally Posted by SiM99_wrk (Post 914667)
Okay.
Does that mean that you're telling me that the other 99.9% of computers making use of the page, where clicking this button doesn't submit the form because I have "return false;" in the onclick event are behaving incorrectly?

All I have to say is that it is safer, according to the standards, to prevent the submit action instead of the click action if want to be 100% sure that data will not be submitted.


All times are GMT +1. The time now is 12:54 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.