Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem posting form data within a bookmarklet.

Status
Not open for further replies.

mattstan

Programmer
Aug 2, 2007
14
GB
Hi,

The following bookmarklet code is modified from the Library Lookup Project.

The 1st 2 lines of the code below extracts a book's ISBN number (worldwide unique ID) from a book's page on a site like Amazon. (It gets the ISBN from the page's URL).

The next 2 lines open a new browser window showing my local library's search page.

Now to get the library's site to search on the ISBN used to be easy, just format a search URL with the ISBN in the right place and that's it. Now they've changed the system and need a form posted. So the code starting with '<body onload...' should submit the form data and so start the search.

javascript:var re=/([\/-]|is[bs]n=)(\d{7,9}[\dX])/i;
if(re.test(location.href)==true){var isbn=RegExp.$2;

void(win=window.open(''LibraryLookup','scrollbars=1,resizable=1,location=1,width=575,height=500'));

'<body onload="document.forms[0].submit()"> <form Method="post"
action="<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value=isbn />
<input name="sb1" value="And" />
<input name="st2" value="title" />
<input name="sv2" value="" />
<input name="sb2" value="And" />
<input name="st3" value="author" />
<input name="sv3" value="" />
<input name="searchLocation" value="talislms" />
<input name="searchCollection" value="1" />
<input name="searchSites" value="-1" />
<input name="searchDates" value="" />
<input name="searchManualDate" value="" />
<input name="searchLanguages" value="" />
<input name="searchFormats" value="" />
<input name="searchOPUS" value="" />
<input name="pageSize" value="20" />
</form></body>';}


There are 2 problems with the code which I can't fix.

i) Firstly the new window showing the library's search page opens but the form gets posted to the original page, the one that was being displayed when the bookmarklet was clicked. I can't work out how to alter the code to make the form get posted to new opened window. Any ideas?

ii) In the form posting code, 5th line down, the value of 'sv1' should be set to the value of the variable isbn (defined in the 2nd line of code at the end of the line), this is the books ISBN number to search for. However in my code the actual letters 'isbn' are posted to the form and not the contents of the isbn variable. What have I done wrong?

Many thanks for any assistance for a javascript newbie.

Regards, etc..
 
1:

Code:
<form Method="post" action="[!]http://[/!][URL unfurl="true"]www.library.islington.gov.uk/TalisPrism/doSearch.do"[/URL] [!]target="LibraryLookup"[/!]>

2:

Code:
<input name="sv1" value=[!]"' + isbn + '"[/!] />

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thank you very much Dan. The isbn variable now works correctly in the form, but unfortunately the target="LibraryLookup" does not. The post data still goes to the original window and not to the newly opened one. It occurred to me that the problem might be that once the newly opened window is open, the window title becomes 'TalisPrism', but changing the target= to that made no difference. Any more ideas how to get the form posted to the new window?

Many thanks again. Regards, etc..
 
Ok, thanks again Dan.

I think my problem is that the form doesn't get posted, it just appears with the data values I set shown in the form. I am guessing that if I can get the form to self-post it will be posted to the correct window, but I'm not sure. Oh well, I'll persevere and any suggestions would be most welcome. Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top