HTML Help: Buttons that link and the people who want them

I’m missing something very obvious. Can someone clue me in on what I’m missing?

I’m trying to do a link button in HTML and it’s not linking.

Here’s the directory structure I’m dealing with:

c:\foo\bar\

In c:\foo is a file called spa.html (ie, it’s path is c:\foo\spa.html )

In c:\foo\bar\ is a file called fon.html (c:\foo\bar\fon.html)

In the fon.html doc, I’ve got the following code:

<FORM METHOD=“LINK” ACTION=“c:\foo\spa.html”>
<INPUT TYPE=“submit” VALUE=“Home”>
</FORM>

But it doesn’t work at all.

Strangely, if I do <a href=“c:\foo\spa.html”>Home</a> I get a link that works just fine. It’s a workaround, but I’m irritated by the fact that I can’t get the button to work.

Help!?

Thanks!

Fenris

For a FORM to work correctly the Action attribute must refer to a CGI action. What you are attempting to do is use a FORM as an ordinary link. Of course it won’t work because it is not a CGI action.

According to W3C standards, “action - This attribute specifies a form processing agent. User agent behavior for a value other than an HTTP URI is undefined.”

Source: http://www.w3.org/TR/html401/interact/forms.html#h-17.3
BTW, you are using an absolute path in your example. Better to use a relative path. Ideally, web pages, or even a complete web site, should be portable enough that you could move it lock, stock and barrel from one server to another with mininal to no tweaking.

You could always just download a button (or make one yourself) from one of those free web gear sites. I’m sure they have buttons which look like the square, grey Windows ones, if that’s what you’re after (hell, you can have a Hello Kitty one if you like).

So if we call it “button.gif”, then you can have:
<a href=“c:\foo\spa.html”><img=“button.gif” BORDER=0></a>

Actaually you can just do:

<form action=“c:\foo\spa.html”>
<input type=“submit” value=“home”>

I think Fenris was mostly correct (it need not be exclusively CGI), but this sort of tricks the browser into doing what you want it to do…You could also take a snapshot of a button and make it an image and use that as a link.

Ooops, I meant “Duckster”.

Also, I tried your way and it worked fine. Are you receiving any error messages? If so, it may just be the URL that is wrong.

Wrong. CGI has nothing to do with it. Here’s an example of a form which gets submitted to a non-CGI url: http://www.codsquad.com/~galt/buttonlink.html
The problem is that “LINK” is not a valid form method. Your choices are GET and POST. “GET” is a link. When you submit a GET form, the form contents are appended as arguments to the action URL specified in the form, and the browser is sent to that URL. So really, all you have to do is change your form’s method to GET.

Snetho, I think you’re right. I have used forms in the past, and they weren’t anything to do with CGI (they are better with CGI though). I’m just wondering if a form will work for a simple link button. Might be overkill. It would remove the problem of having to provide a graphic though, as it is automatically rendered by the browser. I’m still inclined to go with the simple <a> tags.

Also, Duckster is right about the relative addressing. Just call it “spa.html” and it’ll be easier to work with.

What’s to wonder about? It works. Overkill, schmoverkill. It’s not like using a form takes up a significant amount of resources or extra work. If you want the thing to look like a button, it’s a whole lot more sensible to use a real button than it is to fake it with pictures of buttons (because if you fake it, it’s much more work to get the correct button behavior (i.e. pushing in when you click, etc), and it’s more work to get it to look right on varying platforms).

I would override the OnSubmit() action of a form with javascript. Forget the CGI.

Actually, are you getting information from the form, Fenris? You should be able to just put the button in as such:

<input type=“button” OnClick=“javascript function call” />
and forget about the form.

I have also gone the route that erislover suggests. Here’s a scrap of code from a web site I did some work on.

<INPUT TYPE=“button” VALUE=“Song List” ONCLICK=“top.main.location.href=‘songs.htm’”>

That button actually changes the content of another frame, but is easily modified for whatever purpose. This is slightly less code than using form tags, especially if you want multiple buttons on a page linking to multiple pages. The drawback of this is that it may not work on browser’s with javascript diabled.

I think saying “Hey, just use javascript and your problem is solved” overlooks the fact that not a lot of beginners know a darn thing about javascript.

Suggesting javascript: reasonable idea
Assuming javascript is easier than HTML: wrong idea

assuming javascript is easier than CGI? Priceless. :smiley:

Ok, I could have been more detailed.



<input type="button" value="click me" OnClick="top.location.href='http://boards.straightdope.com.sdmb/'" />


Works for me. :slight_smile:

I think the top.xxx refers to a frame. I think location.href will work just fine.
<input type=“button” value=“Home” OnClick=“location.href=‘c:\foo\spa.html’”>

This is actually what I’m using now! Thanks to everyone for all their help.

BTW: I know about relative paths, but I thought it’d make more sense to use absolute paths in the example. In retrospect I don’t know why.

PS: Erislover-Javascript!? :eek: I’m just barely figuring out what’s going on with HTML :wink:

Fenris

Sorry, I guess it is just a matter of how you go about learning something. I copy and pasted javascript from websites long before I knew how to do anything with it.

The absolute best way to learn HTML, if you are teaching yourself, is to view the source of other people’s webpages (though I must say this sort of a button is pretty rare) with a combo of a reference book to look at when you are stumped. I thought this was a good book, though I moved on to something else now.

When you hand-code this there’s some things you never forget! (well, ok, I just hand-formatted it and drew some pics, someone else had done the transcription, and yeah, I’m still not done with the damn thing).

But still, setting up a forwarding/redirect form with CGI is pretty difficult in its own right, especially if you are trying to test it out on your own machine. It is actually kind of surprising that what you suggest isn’t easier to code.

Aaaarrgh! You don’t need JavaScript or CGI! Listen!

galt, what’re you trying to say?

that the only thing wrong with the HTML in the OP is that it says “LINK” instead of “GET”.

METHOD=LINK isn’t valid as far as I know, but it’s funny that the HTML Goodies site uses it, as well as several other sites. Actually, you don’t need a METHOD at all, so putting in a METHOD of LINK or GET or MYMOTHERWEARSCOMBATBOOTS won’t make any difference, the button will still work.

Also, you do need JavaScript. OnClick is a JavaScript event handler.