Bookmarklet - posting data directly (no user action)

M

MS

Hi,

I'm trying to get the LibraryLookup Project bookmarklet to work with a
library search that requires a POST not a GET of the search term.

What I need to do is to create a form in javascript that posts itself
automatically with the required data (already known) as soon as the
bookmarklet is clicked by the user.

I found an old post on Google groups search (from 2002 so long dead) which
gave me some clues.

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="/TalisPrism/doSearch.do">
<input name="" ... ></body>'

The data I want to send is in the following rather long string. The
important bit is the long number '0747566534' (43 chars in to the string),
this is a book's unique ISBN number and gets programatically changed for
whatever book the bookmarklet is initiating a search for.

searchType=advSearch&st1=controlNumber&sv1=0747566534&sb1=And&st2=title&sv2=&sb2=And&st3=author&sv3=&searchLocation=talislms&searchCollection=1&searchSites=-1&searchDates=&searchManualDate=&searchLanguages=&searchFormats=&searchOPUS=&pageSize=10

I know how to create the string but not how to tell the javascript form to
just send the string. Instead of creating 'input names' in the form I want
to just post the string, can this be done? If not can I get around this by
creating the required 'input names' and assigning each of them a value and
then post - all automatically within the javascript bookmarklet and
without any user interaction? How can these things be achieved?

Many thanks,

...matthew
 
J

jamie.ly

If not can I get around this by
creating the required 'input names' and assigning each of them a value and
then post - all automatically within the javascript bookmarklet and
without any user interaction?

Yes, do this.

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="/TalisPrism/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="0747566534" />
<input name="" ... >
</form></body>'

Does that make sense to you? Each ampersand separates a key and value
pair, delimited by an equals sign. Each of these pairs must be
created as an input element like I have done with the first three
pairs above. You can specify the value using the value attribute
which I have used in the input elements above.
 
M

MS

(e-mail address removed) emailed this:
If not can I get around this by
creating the required 'input names' and assigning each of them a value and
then post - all automatically within the javascript bookmarklet and
without any user interaction?

Yes, do this.

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="/TalisPrism/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="0747566534" />
<input name="" ... >
</form></body>'

Does that make sense to you? Each ampersand separates a key and value
pair, delimited by an equals sign. Each of these pairs must be
created as an input element like I have done with the first three
pairs above. You can specify the value using the value attribute
which I have used in the input elements above.

Got it, many thanks I'll give it a go and post the results here.

Cheers,

Matt
 
M

MS

Hi Jamie,

I just started a new thread, cos my question is now so different.
Basically I've done what you suggested but now I can't merge the new code
with the old code which extracts the data and opens a new window. What
happens to me is that the new window opens (on the library's page where
the form data needs to be posted) and then the form gets posted to the old
window!

The new thread has the title:

"Can't join 2 bits of javascript together to get bookmark to work."

If you have a moment maybe you could have a look, if not, and either way
actually, many, many, thanks for helping me with the auto-posting of the
form data.

Regards, etc..


(e-mail address removed) emailed this:
If not can I get around this by
creating the required 'input names' and assigning each of them a value and
then post - all automatically within the javascript bookmarklet and
without any user interaction?

Yes, do this.

javascript:'<body onload="document.forms[0].submit()">
<form Method="post" action="/TalisPrism/doSearch.do">
<input name="searchType" value="advSearch" />
<input name="st1" value="controlNumber" />
<input name="sv1" value="0747566534" />
<input name="" ... >
</form></body>'

Does that make sense to you? Each ampersand separates a key and value
pair, delimited by an equals sign. Each of these pairs must be
created as an input element like I have done with the first three
pairs above. You can specify the value using the value attribute
which I have used in the input elements above.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,139
Latest member
JamaalCald
Top