1

How do I submit a form in jsoup that has a JavaScript function for onclick? There is no submit button, just an anchor tag with button styling.

Example:

<a tabindex="3" onclick="return login();" href="javascript:return login();" onkeypress="hitLogin(event)">Login</a> 

How do I call a JavaScript function with jsoup. Is that even possible? Should I look into some libraries like Node.js or PhantomJS?

Badacadabra
  • 8,043
  • 7
  • 28
  • 49
ThePearl
  • 151
  • 2
  • 14
  • Why did you tag it with [phantomjs] or [nodejs]? If you want to know how to click with it, here you go: http://stackoverflow.com/questions/15739263/phantomjs-click-an-element – Artjom B. Mar 10 '15 at 11:04

1 Answers1

0

The HTML entity parameter onclick takes a string of Javascript that it will run when the node is clicked. href="javascript: (js code here)" does pretty much the same thing. Right now it will eval return login(); which is a call to the Javascript function in the global scope named login.

You should find the login() function and read its source to see what it does. You can either modify login() to perform your form submission, or swap out the event handler to call your own function.

You don't want NodeJS (which is javascript for server-side programming), or PhantomJS (which is a web integration testing tool with a Javascript interface). Neither of them apply to this problem domain. If you want a tool to make event handler binding more convenient, try jQuery. It provides DOM manipulation tools and a widely-used Ajax library.

see https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit or http://api.jquery.com/submit/ for details on how to submit a form in your event handler function.

Just Jake
  • 4,698
  • 4
  • 28
  • 33
  • PhantomJS is a complete programmable browser. Of course it will be used for web testing. Clicking links and see that some stuff happens is exactly what PhantomJS is for. JSoup is really the wrong tool for the job. – Artjom B. Mar 10 '15 at 11:09