admin管理员组文章数量:1410717
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();
本文标签: javascriptSimulate button click in a WebpageStack Overflow
版权声明:本文标题:javascript - Simulate button click in a Webpage - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744794346a2625486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论