Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question 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?

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    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.
    Are you a Help Vampire?

  • #3
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,863
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    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.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #4
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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()">
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #5
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by tomws View Post
    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...

  • #6
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    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 View Post
    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.

  • #7
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by SiM99_wrk View Post
    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">
    Last edited by Kor; 01-22-2010 at 04:11 PM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #8
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    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.

  • #9
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by SiM99_wrk View Post
    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?
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #10
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Kor View Post
    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 View Post
    Do you have other submit/image inputs within the same form?
    Quote Originally Posted by SiM99_wrk View Post
    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.

  • #11
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by SiM99_wrk View Post
    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.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •