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 . 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
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
Share Improve this question edited Jan 18, 2011 at 14:06 Pikoh asked Jan 18, 2011 at 12:03 PikohPikoh 7,71331 silver badges56 bronze badges 2- The code on that page is very long and hard to follow. It's much better to write a minimal testcase and share that. sscce – Stewart Commented Jan 18, 2011 at 12:15
- Stewart, the fact is that i don't own the page. It's a goverment web and i just want to be able to use it from my android app. Thx for caring anyway – Pikoh Commented Jan 18, 2011 at 12:26
3 Answers
Reset to default 3You 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.
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
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();