By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,030 Members | 1,207 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,030 IT Pros & Developers. It's quick & easy.

Anchor link around input button

P: n/a
Hey, I know of two ways to place a link on an HTML page; (1) use the
anchor element, and (2) use javascript to respond to an event (such as
onclick) and set the location.

I recently started using anchors more, and I eventually happened to
try to put an anchor link around an input button, as you can see:

<a href="example.com"><input type="button" value="Example" /></a>

This worked fine in Firefox and Chrome, but it doesn't have any effect
in IE (you can push the button, but nothing happens). Why is this, how
can I fix it, and should I just stick with the javascript method as
shown below:

<input type="button" value="Example" onclick="location.href =
'example.com';" />

Thanks.
Nov 4 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"bgold12" <bg*****@gmail.comwrote in message
news:3e**********************************@b31g2000 prb.googlegroups.com...
Hey, I know of two ways to place a link on an HTML page; (1) use the
anchor element, and (2) use javascript to respond to an event (such as
onclick) and set the location.

I recently started using anchors more, and I eventually happened to
try to put an anchor link around an input button, as you can see:

<a href="example.com"><input type="button" value="Example" /></a>

This worked fine in Firefox and Chrome, but it doesn't have any effect
in IE (you can push the button, but nothing happens). Why is this, how
can I fix it, and should I just stick with the javascript method as
shown below:

<input type="button" value="Example" onclick="location.href =
'example.com';" />
Why do you want to turn buttons into links? If you just want your links to
look like buttons, then why don't you style them that way?

Nov 4 '08 #2

P: n/a
On Mon, 3 Nov 2008 19:48:43 -0800 (PST), bgold12 <bg*****@gmail.com>
wrote:
>Hey, I know of two ways to place a link on an HTML page; (1) use the
anchor element, and (2) use javascript to respond to an event (such as
onclick) and set the location.

I recently started using anchors more, and I eventually happened to
try to put an anchor link around an input button, as you can see:

<a href="example.com"><input type="button" value="Example" /></a>

This worked fine in Firefox and Chrome, but it doesn't have any effect
in IE (you can push the button, but nothing happens). Why is this, how
can I fix it, and should I just stick with the javascript method as
shown below:

<input type="button" value="Example" onclick="location.href =
'example.com';" />

Thanks.
A standard button is a link if done correctly. Which won't work if JS
is off.
If ya want to do it your way, create an image that looks like a button
and then use anchors. Works with JS off or on.

Nov 4 '08 #3

P: n/a
richard wrote:
A standard button is a link if done correctly. Which won't work if JS
is off.
However, unless I've missed some trick, the resulting URL will have at
least a trailing "?". This may be browser-specific, but I don't think so.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Nov 4 '08 #4

P: n/a
Swifty wrote:
richard wrote:
>A standard button is a link if done correctly. Which won't work if JS
is off.

However, unless I've missed some trick, the resulting URL will have at
least a trailing "?". This may be browser-specific, but I don't think so.
The lesson here is use a *link* for a *link*, not a form control...

--
Take care,

Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
Nov 4 '08 #5

P: n/a
Swifty wrote:
richard wrote:
>A standard button is a link if done correctly. Which won't work if JS
is off.

However, unless I've missed some trick, the resulting URL will have at
least a trailing "?". This may be browser-specific, but I don't think
so.
It's not browser-specific. And "richard" is of course wrong as usual, with
just enough factoids accidentally included to confuse many people.

A button as such is not even a pseudolink. When wrapped inside a form, it
somewhat corresponds to a link. Using the button resembles then following a
link to the URL in the action attribute of the form, _except_ that you lose
most of the functionality of links.

The trailing "?" is not a problem since it is ignored by servers unless you
do something extravagant to make them treat it in some special way.
Actually, "?" followed by a string is ignored if the server has not been
programmed or configured handle it.

If you use method="POST" in the <formtag, the "?" won't be appended, but
who cares?

--
Yucca, http://www.cs.tut.fi/~jkorpela/

Nov 4 '08 #6

P: n/a
On 2008-11-04, bgold12 wrote:
Hey, I know of two ways to place a link on an HTML page; (1) use the
anchor element, and (2) use javascript to respond to an event (such as
onclick) and set the location.

I recently started using anchors more, and I eventually happened to
try to put an anchor link around an input button, as you can see:

<a href="example.com"><input type="button" value="Example" /></a>
Why do you need a button? You can style the link to look like one:

<a href="example.com"
style="background: #ddd; color: black; border: 2px outset #555">
Example</a>
This worked fine in Firefox and Chrome, but it doesn't have any effect
in IE (you can push the button, but nothing happens). Why is this, how
can I fix it, and should I just stick with the javascript method as
shown below:

<input type="button" value="Example" onclick="location.href =
'example.com';" />

--
Chris F.A. Johnson, webmaster <http://Woodbine-Gerrard.com>
================================================== =================
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Nov 4 '08 #7

P: n/a
Jukka K. Korpela wrote:
The trailing "?" is not a problem since it is ignored by servers unless
you do something extravagant to make them treat it in some special way.
Actually, "?" followed by a string is ignored if the server has not been
programmed or configured handle it.

If you use method="POST" in the <formtag, the "?" won't be appended,
but who cares?
Just in case anyone is curious, a CGI script is passed the URI in the
environment variable REQUEST_URI.

I have some webpages that use that value to build other links to the
same page, but with optional parameters.

So starting with http://server.com/page that submits a form to the same
URL with ACTION=GET, I end up with the URI being http://server.com/page?
If I now use this to build links with parameters, by appending "?parms"
to the URI value then I end up duplicating the "?". After a few passes,
I can end up with several "?"s in a row. Of course, it is easy to work
around this, but finding a way to stop the "?" getting into the browsers
Location: field in the first place would be the best in many ways.
Especially as a way of stopping the email from people with nothing
better to do than ask me why my URL's sometimes have an "?" on the end.
And yes, I have had such mail. With sufficient users, you eventually get
asked every conceivable question. I suppose eventually I'll receive the
complete works of Shakespeare, as a mistype.
See http://www.swiftys.org.uk/wiz?487

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Nov 4 '08 #8

P: n/a
In article <sc******************************@brightview.com >,
Swifty <st***********@gmail.comwrote:
I suppose eventually I'll receive the
complete works of Shakespeare, as a mistype.
See http://www.swiftys.org.uk/wiz?487
Why do you suppose this and yet quote something that suggests otherwise?

--
dorayme
Nov 4 '08 #9

P: n/a
dorayme wrote:
>I suppose eventually I'll receive the
complete works of Shakespeare, as a mistype.
See http://www.swiftys.org.uk/wiz?487

Why do you suppose this and yet quote something that suggests otherwise?
I can see both sides of the argument. That's the advantage of being
two-faced.

--
Steve Swift
http://www.swiftys.org.uk/swifty.html
http://www.ringers.org.uk
Nov 5 '08 #10

P: n/a
In article <rZ******************************@brightview.com >,
Swifty <st***********@gmail.comwrote:
dorayme wrote:
I suppose eventually I'll receive the
complete works of Shakespeare, as a mistype.
See http://www.swiftys.org.uk/wiz?487
Why do you suppose this and yet quote something that suggests otherwise?

I can see both sides of the argument. That's the advantage of being
two-faced.
OK, but my complaint is you being three-faced. You see, if you had
suggested both things at the same level of suggestion, that would be two
faced. But that is not what you did. You supposed one thing openly, you
suggested another thing and, because of the relations between the
suppositon and the suggestion, a third thing was borne at another level.
I don't think you realise how evil you are. <g>

--
dorayme
Nov 5 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.