0

I'm trying to use a form to pick up a value from a webpage that a client inputs. This can be anything. The idea is to search multiple websites by opening new tabs having constructed the required URL using a function.

I can open one tab and do the search but multiple functions do not run. I've tried the usual funct={funct1;funct2} but cannot get this to work.

Here is the working part of the script

function process(){var url="http://jobs.rsc.org/searchjobs/?keywords=" + document.getElementById("url").value;
window.open(url,'_blank' // <- This is what makes it open in a new window.);
return false;}
<form onsubmit="return process();">Job Description: <input name="url" id="url" type="text"><input value="go" type="submit"></form>

Adding additional functions and calling <form onsubmit="return process();return process1()"; Also doesn't seem to work I either get one or the other functions or neither. The script just searches a chemistry jobsite but it could be anything and the urls are constructed differently depending on the site.

j08691
  • 204,283
  • 31
  • 260
  • 272
  • Are these websites (that you're opening in the tabs) within the same domain as the original website that your javascript is running in? If not, you'll be hitting the [Same Origin Policy](http://en.wikipedia.org/wiki/Same-origin_policy)... unless you have [Cross-Origin Resource Sharing](http://www.w3.org/TR/access-control/) setup on the **other** websites – freefaller Mar 05 '15 at 17:48
  • Writing `return process();` means that `return process1()` will never be executed (since the handler has already returned to its caller). – Frédéric Hamidi Mar 05 '15 at 17:48
  • Is it safe to assume you didn't mean to comment out the closing parenthesis on your window.open line? – Daved Mar 05 '15 at 17:49
  • What do you mean by "the usual {funct1,funct2}"? There is no such syntax in JS. – s-ol Mar 05 '15 at 17:51
  • Thanks for the fast responses to answer the questions. The tabs will open in different domains – stevenagesoftware Mar 05 '15 at 18:03
  • http://stackoverflow.com/questions/3910736/how-to-call-multiple-javascript-functions-in-onclick-event is where the multiple solution came from function myfunct = {funct1();funct2()} came from. The open parenthesis was an error although it seems to work. – stevenagesoftware Mar 05 '15 at 18:06
  • Removing return stops the tab opening. I'm guessing the script isn't called. – stevenagesoftware Mar 05 '15 at 18:08
  • Found it! http://stackoverflow.com/questions/5752897/how-to-create-a-search-box-that-open-multiple-search-results-from-different-sear This will do what I need. Thanks for your help all. – stevenagesoftware Mar 05 '15 at 18:50

1 Answers1

0

By using return you tell JS to stop execution at that point:

function donttellmeyourname() {
  return 4;
  console.log("I said I wouldn't!"); // this will never print!

This also aplies to the HTML handlers. A working way would be:

<form onsubmit="process(); process1(); process2();">...</form>
s-ol
  • 1,674
  • 17
  • 28