Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > HTML > using hyperlinks as submit buttons

Reply
Thread Tools

using hyperlinks as submit buttons

 
 
Alexander Weiner
Guest
Posts: n/a
 
      06-27-2006
Hello,

I have several sites, that includes the forms in an <form method=post
action="...">.

It is absolutely necessary, that all the parameters are send by post and not
by get. Now I want to insert Hyperlinks <a href... in this form section. But
here I have to put the parameters in the url via get.

Is there a way to use the hyperlinks like a submit button that sends all the
elements in the form section via post? JavaScript is allowed.

Thanks for all answers.


 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      06-27-2006
Alexander Weiner wrote:

> It is absolutely necessary, that all the parameters are send by post and not
> by get. Now I want to insert Hyperlinks <a href... in this form section. But
> here I have to put the parameters in the url via get.


The best solution is to forget it. Links go places. Buttons send data
places. They send a strong message to the user telling them what is
going to happen. Its poor usability if they send the wrong message.

That said, you can (eugh) use CSS to style buttons to look like links.

 
Reply With Quote
 
 
 
 
jojo
Guest
Posts: n/a
 
      06-27-2006
Alexander Weiner schrieb:
> Hello,
>
> I have several sites, that includes the forms in an <form method=post
> action="...">.
>
> It is absolutely necessary, that all the parameters are send by post and not
> by get. Now I want to insert Hyperlinks <a href... in this form section. But
> here I have to put the parameters in the url via get.
>
> Is there a way to use the hyperlinks like a submit button that sends all the
> elements in the form section via post? JavaScript is allowed.
>
> Thanks for all answers.
>
>


<script type="text/javascrit" language="javascript">
document.SomeForm.submit()
</script>
<body>
<form name="SomeForm" method="post" action="...">
..
..
..
</form>
</body>

Should work with all browsers.
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      06-27-2006
jojo wrote:

> <script type="text/javascrit" language="javascript">
> document.SomeForm.submit()
> </script>
> <body>
> <form name="SomeForm" method="post" action="...">


> Should work with all browsers.


No it shouldn't.

In browsers that do support JavaScript, it should cause them to go "Eh?
What's this text/javascrit thing? I'll ignore that."

In browsers that support JavaScript, and have JavaScript turned on and
can recover from that error, it will cause them to go
"document.SomeForm? Nope, haven't seen a document.SomeForm yet." and
throw an error.

In browsers that don't support JavaScript, or have JavaScript turned
off, it will do nothing at all.

 
Reply With Quote
 
jojo
Guest
Posts: n/a
 
      06-27-2006
David Dorward schrieb:
> jojo wrote:
>
>> <script type="text/javascrit" language="javascript">
>> document.SomeForm.submit()
>> </script>
>> <body>
>> <form name="SomeForm" method="post" action="...">

>
>> Should work with all browsers.

>
> No it shouldn't.
>
> In browsers that do support JavaScript, it should cause them to go "Eh?
> What's this text/javascrit thing? I'll ignore that."


Just a spelling-error, of course it should be "text/javascript"

> In browsers that support JavaScript, and have JavaScript turned on and
> can recover from that error, it will cause them to go
> "document.SomeForm? Nope, haven't seen a document.SomeForm yet." and
> throw an error.


Yes, they have seen. Look at the form-tag...
And ASFAIK it is possible to call form-elements by thier name without
any "getElementById("")" or something else...

And if some Browser doesn't support that: document.forms[0].submit()
Or give the Form an ID and use document.getElementById("ID")

>
> In browsers that don't support JavaScript, or have JavaScript turned
> off, it will do nothing at all.
>


Yes, I know, but I think you missed the
> JavaScript is allowed.

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-27-2006
Alexander Weiner wrote:
> It is absolutely necessary, that all the parameters are send by post and not
> by get.


Then you _must_ submit from a <form>, not an <a> link (OK, so you
could do some AJAX-like thing too)

You have three options: CSS, JavaScript or a lot of JavaScript.

For CSS you make a bog-standard <form> with a submit button on it, then
you use CSS to make it look as much like an <a> as possible. This is
the simplest and most robust.

For JavaScript then you code a HTML <a> as normal, code a <form> as
well, then you use JavaScript to trap the <a onclick=... > event and
use it to do a form submit instead. jojo had the right idea, but coded
it unworkably badly. Return false afterwards, or else the <a> will
still try and navigate somewhere. What to set the <a href=... >
attribute to depends on what you wnat to happen for non-JS users. If
you want them to be disabled safely, then use href="#". If you permit
them to submit via a GET, but at least have something still working,
then set this link in the href as normal. Returning false will guard
against double submissions.

With a whole bunch of JavaScript and AJAX, you can do it without the
extra HTML coding.

 
Reply With Quote
 
jojo
Guest
Posts: n/a
 
      06-27-2006
Andy Dingley <(E-Mail Removed)> schrieb:

> jojo had the right idea, but coded
> it unworkably badly.


OK, you're right, seems like I haven't really thought about it before
posting it, I'm sorry. I forgot that the JS-Function has to be started
by click on an hyperlink...

This code will do it:

function SubmitForm(a){
document.forms[0].submit(); //if it is the first form in your code
return false;
}

To call the code add onclick="SubmitForm()" to your hyperlink.
Or, if it is not supposed to work for users with JavaScript disabled you
can set the href to "javascript:SubmitForm()", a Browser without
JavaScript will ignore this.
 
Reply With Quote
 
David Dorward
Guest
Posts: n/a
 
      06-27-2006
jojo wrote:

> > In browsers that support JavaScript, and have JavaScript turned on and
> > can recover from that error, it will cause them to go
> > "document.SomeForm? Nope, haven't seen a document.SomeForm yet." and
> > throw an error.

>
> Yes, they have seen. Look at the form-tag...


The form tag that appears in the document AFTER the script has
executed?

When the script executes there is no form.

> > In browsers that don't support JavaScript, or have JavaScript turned
> > off, it will do nothing at all.


> Yes, I know, but I think you missed the
> > JavaScript is allowed.


The requirements allowing the use of JavaScript doesn't magically cause
all browsers to support it (nor does it make it a good idea to depend
on JavaScript).

 
Reply With Quote
 
jojo
Guest
Posts: n/a
 
      06-27-2006
David Dorward schrieb:
> jojo wrote:
>
>>> In browsers that support JavaScript, and have JavaScript turned on and
>>> can recover from that error, it will cause them to go
>>> "document.SomeForm? Nope, haven't seen a document.SomeForm yet." and
>>> throw an error.

>> Yes, they have seen. Look at the form-tag...

>
> The form tag that appears in the document AFTER the script has
> executed?
>
> When the script executes there is no form.


I'm sorry, look at my reply to Andy's message.

>>> In browsers that don't support JavaScript, or have JavaScript turned
>>> off, it will do nothing at all.

>
>> Yes, I know, but I think you missed the
>>> JavaScript is allowed.

>
> The requirements allowing the use of JavaScript doesn't magically cause
> all browsers to support it (nor does it make it a good idea to depend
> on JavaScript).


Of course it doesn't. But I interpreted this as a "I know about the
disadvantages of JavaScript and can live with it".
 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      06-27-2006
jojo wrote:

> OK, you're right, seems like I haven't really thought about it before
> posting it,


_Please_ learn to code with some semblance of decent style before
posting these rubbish snippets.

> can set the href to "javascript:SubmitForm()",


In case you don't know already, don't ever use this
href="javascript:..." bogosity.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
User name and password to activate buttons and hyperlinks on website jonny ASP .Net 4 10-12-2007 04:19 PM
dynamically add hyperlinks and buttons to a datagrid Richard Jonker ASP .Net Datagrid Control 2 10-03-2006 05:48 AM
Radio Buttons & Hyperlinks? Cerebral Believer HTML 18 09-27-2006 07:01 AM
Forms with multiple submit buttons vs 'form' objects with single 'submit' methods neil.fitzgerald@ic.ac.uk Python 4 04-14-2006 04:58 PM
Hyperlinks vs Buttons ? =?Utf-8?B?SXJmYW4gQWtyYW0=?= ASP .Net 5 02-13-2005 01:33 PM



Advertisments