Reputation: 7703
i'm trying to code an application for Android that fills up a form in a webpage,submits it and parse results to show them. I'm using javascript to fill up the fields and then call the form's action, but it doesn´t work. I have studied the web html code, but i believe it uses JSF to display and handle the form. Is there any way to simulate the submit button click just as if i press it physically? In case anyone want to take a peak in the code, web url is http://www.transportedecantabria.es. The fact is i'm not a big expert in web programming and i'm a bit lost :).Thx and sorry about my english
EDIT: I've also tried this:
javascript:var elementToGet = "frmBusqueda:j_id29";
var form = document.forms["frmBusqueda"];
var button = form.elements[elementToGet];
button.click();
But it keeps reloading the web, not giving me the submit result
Upvotes: 2
Views: 6983
Reputation: 26183
You should be able to call the click()
method on the button object to fire it, though it would probably be better to call the submit()
method on the form object.
Upvotes: 4
Reputation: 7703
This code made the trick:
javascript:var elementToGet = "frmBusqueda:j_id29";
var form = document.forms["frmBusqueda"];
var button = form.elements[elementToGet];
button.click();
Thx all for your help
Upvotes: 1
Reputation: 845
You can use
document.forms
to retrieve the form elements within the current document.
If you want to submit the first form:
var firstForm = document.forms[0];
firstForm.submit();
Upvotes: 0