There I have a button that is hidden from the user but want it to be clicked by default like with a check box if you want it to be checked by default you add the checked attribute is there any way you could do the same thing with a button here is my code
<input id="submit" type="hidden" value="Reverse Geocode" autofocus>
There I have a button that is hidden from the user but want it to be clicked by default like with a check box if you want it to be checked by default you add the checked attribute is there any way you could do the same thing with a button here is my code
<input id="submit" type="hidden" value="Reverse Geocode" autofocus>
Share
Improve this question
edited May 18, 2018 at 5:12
xxxmatko
4,1422 gold badges19 silver badges24 bronze badges
asked May 18, 2018 at 5:07
Arnav NathArnav Nath
812 gold badges3 silver badges13 bronze badges
5
|
5 Answers
Reset to default 7You can do as following:
<script type="text/javascript">
document.getElementById("submit").click();
</script>
May be you can do the following:
document.getElementById('chkTest').addEventListener('click', function(){
if(this.checked)
document.getElementById('submit').click();
});
document.getElementById('submit').addEventListener('click', function(){
alert('button clicked');
});
<input id="submit" type="hidden" value="Reverse Geocode" autofocus />
<input type="checkbox" id="chkTest" /> Check To Click The Button
At first, your button is not a button. It's a a hidden field.
In order to make it a button, change type="hidden"
to type="button"
. To make it invisible to the user, you could use inline styles like this: style="display: none;"
.
As a result, your button looks like this:
<input id="submit" style="display: none" type="button" value="Reverse Geocode">
Now, to click it, simply call the click()
method:
document.getElementById('submit').click();
Trigger click event on the button as soon as document is ready.You have to write the click event as shown below.
$(document).ready(function(){
$("#yourButtonId")[0].click();
});
Now i understand your question, You want default click in your submit button. Try click event, It will trigger the submit.
<script>
$('#submit').trigger('click');
</script>
In JavaScript
document.getElementById("submit").click();
click event
of the buttonwindow.load()
or if you have a function assigned to it just call it. – vikscool Commented May 18, 2018 at 5:11