0

I would like to create a JavaScript that adds a search box to HTML pages, then with the input it first URL encodes it and adds it to a URL (e.g., http://www.ncbi.nlm.nih.gov/pubmed?term= could be the base URL) and creates a new popup Window opening the end URL (i.e., the result of the addition of the URL encoded input and the base URL). e.g., if the Input for a PubMed search (the same URL as in the example above) is nicotine[TI] AND review[PT] then the output URL that the new window would open to would be: http://www.ncbi.nlm.nih.gov/pubmed?term=nicotine%5BTI%5D+AND+review%5BPT%5D.

1 Answer 1

0

try

 var Form = $("#myForm");   
 Form.onsubmit = function() {
 var baseUrl = 'http://www.ncbi.nlm.nih.gov/pubmed?term=';
 var search = $("#input").val();
 var Url = baseUrl + search ;
 var encodedUrl = encodeURIComponent(Url);
 var w = window.open(encodedUrl ,'Popup','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=500,height=500');
 this.target = 'Popup';
 alert(encodedUrl);
};

<form id="myForm" >
 <input type="text" id="input">
 <button type="submit" >Submit</button>
</form>
1
  • Calling that script Search box.js and calling it by a HTML file: <!DOCTYPE html> <html> <head> <title>Search box for PubMed</title> </head> <body> <script src="Search box.js"></script> </body> </html> gives an empty page.
    – Josh Pinto
    Mar 29, 2015 at 9:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.