Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
36
rated 0 times [  39] [ 3]  / answers: 1 / hits: 12581  / 11 Years ago, fri, december 6, 2013, 12:00:00

I'm trying to click on a submit button and submit a form using purely javascript. I have tried:



document.getElementById('sell_form').submit();


and



for(var i=0;i<document.getElementsByName('operation').length;i++){
if(document.getElementsByName('operation')[i].value=='Sell'){
document.getElementsByName('operation')[i].submit();
}
}


but I just can't get it. Can anyone show me how I could do this?



Thanks in advance.



The web code is:



<form id=sell_form class=ajaxform action=/member/sell method=post>
<div id=result class=popup> </div> //hidden
<div class=c-box-body>
<table width=100% border=0>
<div style=text-align:center>
<br>
<input type=hidden value=13 name=pair> //hidden
<input type=hidden value=Sell name=type> //hidden
<input type=submit value=Calculate name=calculate>
<input type=submit value=Sell name=operation> //**This is the one I'm trying to click on
<input type=reset value=Clear>
</div>
</div>
</form>


What makes this difficult is that the web page is not mine (I'm using greasemonkey in firefox which is essentially and onload javascript event)


More From » forms

 Answers
11

I was able to to it with:



var element = document.querySelector('#sell_form input[name=operation]');  
if (element) {
element.click();
}

[#49799] Thursday, December 5, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ammonjesseg

Total Points: 170
Total Questions: 110
Total Answers: 98

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
;