1

I'm trying to click a button programmatically with javascript. Using the following code works fine:

var pbutton= document.getElementById('psubmit');
pbutton.click();

but when I try it on my mobile browser it wont fire the click event. Is their another way to do this for Mobile Browsers?

user2423476
  • 2,115
  • 8
  • 28
  • 40
  • 1
    If you don't mind using some jQuery you can try using `$("#psubmit").trigger("click");` – Jaay Jan 15 '15 at 07:53
  • possible duplicate of [Using click() on links in Android Stock Browser not working](http://stackoverflow.com/questions/16936066/using-click-on-links-in-android-stock-browser-not-working) – dirkk Jan 15 '15 at 08:26
  • possible duplicate of [How can I trigger a JavaScript event click](http://stackoverflow.com/questions/2381572/how-can-i-trigger-a-javascript-event-click) – jazZRo Jan 15 '15 at 08:29

3 Answers3

0

You will need to implement jquery for this or use a simple javascript.

You can add following code to implement through pure javascript

document.getElementById('psubmit').click(); 

You can check jsfiddle here

or for jquery you can implement by

$(document).ready(function(){
$('#btn').click(function(){ alert("JQuery Running!");});
 $( "#btn" ).trigger( "click" );
});

You can check jsfiddle here

For both this to work you need to have id property defined. And to implement jquery you will need to add jquery file in you code. Hope this helps. Cheers :)

Aadil Keshwani
  • 1,385
  • 1
  • 18
  • 29
0

You could use jQuery

$(function(){
  $('#psubmit').click()
});
phadej
  • 11,947
  • 41
  • 78
0

Try using jquery:

$('psubmit').live("click",function(){
     //Function code here
});
marco burrometo
  • 1,055
  • 3
  • 16
  • 33