473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

href onclick

I have set up the onclick event of an href so that it submits a form
and returns false. I'm returning false to prevent the browser from
actually going to the page. However, because I have the form
submission as part of the onclick event, it seems like I'm not being
successful in preventing that.

Is there some way I can make it so that the browser doesn't go to the
page?

thnx,
Chris

Sep 11 '07 #1
3 2682
On 11 Set, 14:20, Christoph <christoph.bo...@gmail.comwrote:
I have set up the onclick event of an href so that it submits a form
and returns false. I'm returning false to prevent the browser from
actually going to the page. However, because I have the form
submission as part of the onclick event, it seems like I'm not being
successful in preventing that.

Is there some way I can make it so that the browser doesn't go to the
page?

thnx,
Chris
this code should do it:

<a href="javascript: void foo()">text</a>

or

// here foo() MUST return false that is then returned to onclick
<a href="#" onclick="return foo()">text</a>

Bye

Sep 11 '07 #2
Lee
Christoph said:
>
I have set up the onclick event of an href so that it submits a form
and returns false. I'm returning false to prevent the browser from
actually going to the page. However, because I have the form
submission as part of the onclick event, it seems like I'm not being
successful in preventing that.

Is there some way I can make it so that the browser doesn't go to the
page?
Are you trying to see how far you can distort the normal functionality?
Using a link as something other than a link, and then trying to use
form submission for something other than what it was designed to do?

Submitting a form loads the new page sent back from the server.
If you don't want to load a new page, you don't want to submit a form.
Find another method of sending your data to the server.
--

Sep 11 '07 #3
Christoph wrote:
I have set up the onclick event of an href so that it submits a form
and returns false.
Wrong approach.
I'm returning false to prevent the browser from actually going to the page.
Why should it? You are canceling the click event of the link, thereby
preventing its default action, which is to navigate to the resource its
`href' attribute designates.
However, because I have the form submission as part of the onclick event,
it seems like I'm not being successful in preventing that.
Yes, your approach is wrong. When the form is submitted through your
event listener, navigation to another resource has already taken place.
Is there some way I can make it so that the browser doesn't go to the
page?
Use the correct approach: a submit button (input[type="submit"] or
input[type="image"]) and the `onsubmit' event handler of the `form'
element to which you return `false' when the form should not be
submitted. You will have to test server-side anyway.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 11 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Jez | last post by:
Hi, I've created a function which opens a popup window containing a calendar. When a day is clicked, the date is entered into a text box on the parent page and the popup is closed. The link...
11
by: Dana Smith | last post by:
Can anybody explain why when I have a hyperlink on a page with the code similar to below, after the user clicks on the link, the desired window opens but the page with the hyperlink changes to a...
14
by: Brandon Hoppe | last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is for Netscape 4 only....
5
by: Mike | last post by:
In my previous post, I wrote: > ... > GOAL: (very simple) Provide a hyperlink which, when clicked, > calls a javascript function which opens a new URL. > ... > PROBLEM: The following code...
2
by: Kevin Lyons | last post by:
Hello, Can anyone assist me with what I am trying to do with the following code (six different scenarios to try to make the functionality work correctly)? I want to always (and ONLY) display...
4
by: Jamie Jackson | last post by:
I know that it's possible to return false in an onClick to disable a link. Is there a way to do this within the HREF attribute? Something like: <a href="javascript: return false;"> ? Thanks,...
4
by: Jerry Sievers | last post by:
JS Programmers, "I'm a server-side coder PHP, Postgres etc... My question; Given the following anchor <a href="http://www.somesite.com/somefile.html">link text</a> Is there a way to code an...
53
by: usenet | last post by:
See <ul> <li><a name="link1" onClick="alert(this.name);return false;" href="#">Link1</a></li> <li><a name="link2" href="javascript:alert(this);">Link2</a></li> <li>Item 3</li> </ul> ...
13
by: Logos | last post by:
There seems to be a serious difference between how FF an IE handle an anchor with an href containing a # and an onclick event. If the onclick event returns false, IE does not change...
5
by: dangt85 | last post by:
Hello, I have the following page: ... <style type="text/css"> body { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; }
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.