Muffinresearch Labs by Stuart Colville

Getting relative form actions with javascript | Comments (1)

Posted in Browsers, Code on 24th October 2006, 11:10 pm by Stuart

The other day I needed to get data from a form and manipulate the “get” manually through javascript. For that to happen I needed to obtain the action attribute of the form. The action of this specific form had to be a relative url. What I found through testing was that whether I used getAttribute('action') or action the relative url would sometimes become a fully qualified url depending on which method you used in which browser.

Method IE6 IE7 Firefox Opera Safari
getAttribute(‘action’) Relative Relative Relative Fully Qualified Relative
action Relative Relative Fully Qualified Fully Qualified Relative

The end result of this little oddity is that you are best using fully qualified urls in form actions. However if you do need to use a relative url as an action you need to be careful to make sure that you end up with what you are expecting. For example I’d use getAttribute(‘action’) and just fix the result coming from opera by checking for the presence of ‘http’.

See the simple example

Post Tools

Comments: Add yours

1. On November 1st, 2006 at 3:30 pm Isofarro said:

Good to know the relative URL on form action reacts the same way as the href attribute on links. I think this has to do with the difference between a node property (form.action), and a node attribute(form.getAttribute(‘action’)).

Its handy way of dealing with relative URLs.







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(2)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

© Copyright 2004-12 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.591s.