January 19th, 2006
Using anchor links to submit HTML forms
One of the components that come with Prado is the TLinkButton. It is a normal anchor link that acts like a regular HTML form input submit button. This component requires javascript to submit the form. E.g.
<a id="link1" href="#">Click Me</a>
We want of course to avoid in-line javascript on the anchor link, so this mean we need to attach an onclick handler to the link.
Event.observe("link1", "click" function(e) { //.... find the theForm element some how theForm.submit(); //Event.fireEvent(theForm,"submit"); //same as above });
No problem so far, if you click on the link, the form will be submitted. However a strange behaviour exists in Internet Explorer 6, if there are in-line javascript code in the href attribute, e.g. href=“javascript:myfunction()” then a strange thing can happen. If myfunction() does not submit a form, then clicking the link will not submit the form, even though your observed function was called (hence calling theForm.submit() within).
So, avoid inline javascripts if possible.
The next problem is, what to put in the href attribute for TLinkButton such that each link are unique? May be “#uniqueID”?
August 29th, 2006 at 5:46 am
I’m constantly amazed at the sheer stupidity of Internet Exploder, and this problem vexxed me for quite a while before I came across your post. I had a JavaScript function that I was calling in my links that set a hidden form field value and then submitted the form. Because I wanted to handle it in the onClick event, I added href=”javascript:void(0);” to my links and called the function in the onClick. As you can imagine, this didn’t work. When I pulled the code out of the onClick and made it the href attribute, it magically worked! So thank you for pointing this one out.
January 27th, 2007 at 12:23 am
hi 2 all.
hello world! It is nice site. Keep working!
best regards
i found you here http://google.com ^^
February 1st, 2007 at 8:40 pm
thanks a lot it helped me alot .. but i tried with the function and it works in IE.
April 6th, 2007 at 12:03 am
The site looks great ! Thanks for all your help ( past, present and future !)
May 5th, 2007 at 10:25 pm
Looks great! I found lots of intresting things here. Many thanks.
September 1st, 2007 at 12:26 am
I assume with this type of link you are going to be using a fallback check. I mean, I assume you would have a NOSCRIPT in there somewhere containing an actual HTML INPUT SUBMIT button otherwise if Javascript is disabled or the user is using a a text-only browser etc… then nothing would work…
Also, (excuse my ignorance as I just got to this page off Google).. but..
wouldn’t it be a better method to use
and just use CSS to style the button so it looks like A HREF clickable link?
..and if you want to then do something with an Anchor have an onClick on the SUBMIT button that goes somewhere.. at least then if Javascript fails you still have a valid submit button even if the Javascript fails…
Might just be me but relying on “onClicks” to do important things, without fallback is just a bit silly
I’m sure there’s a fallback though if Javascript doesn’t work!
b-bye
September 1st, 2007 at 12:28 am
Ok.. this form didn’t do any HTMLENTITY check on my code so my sentence was broken.. where it said “wouldn’t it be a better method to use…” it should have been folloed with this…
(assun this is an input field…
INPUT TYPE=”SUBMIT” VALUE=”CLICK ME” ID=”LINK1″ CLASS=”submitButtonLink”
Now fix this form so it replaces html code with > and <