Monday, March 14, 2005

Bookmarklets, Form POST Data and More Postcode Info...

One thing that has been nagging me about bookmarklets has been how to use them to pass information to a webpage/service tht accepts form POST data.

Easy enough with a GET, of course, you just add the variable name and the required data to the URI. But for services like this list of bus/coach services which only accept FORM data, I was stumped as to how to do it...

...until someone suggested making a form... a quick search later, and this page on Smart Bookmarks and Bookmarklets showed the way forward...

My first attempt pulled the postcode <link /> info from a page and then tried to create a new document to hold the form...but that seemed to hang, so now the change is made to the loaded page directly... Naughty, I know, but there we go - if you can show me how to get a working bookmarklet that creates the form in a new document, please add a comment...

So, for the record, this is the script:

javascript:void(d=document);
void(el=d.getElementsByTagName('link'));
for(i=0;i<el.length;i++){
if(el[i].getAttribute('rel').indexOf('postcode')!= -1){
uri='http://www.carlberry.co.uk/rfnlistl.asp';
f=d.createElement('form');
f.method ='post';
f.action=uri;
i0=d.createElement('input');
i0.type='text';
i0.name='IL5';i0.value=foaf;
f.appendChild(i0);
d.body.appendChild(f);
f.submit();
};
};

and this is the bus timetable bookmarklet.

If you want to give it a try, this whole blog is postcode <link /> enabled...

Del.ici.ous tags:

0 Comments:

Post a Comment

<< Home