Link to home
Start Free TrialLog in
Avatar of gaurih
gaurih

asked on

call the onclick event inside the input type=submit

This is tricky question but it would be really great If you provide me the solution

I have <input type="submit" onClick="call(parameter)">. Is thathandle this function from external Jquery function.

Problem is I am not able to click this button since it has already onlcik functionality. Is there any way to do this?
Avatar of Kiran Sonawane
Kiran Sonawane
Flag of India image

Look at below code

button click event is called when text changed in textbox

Demo http://jsfiddle.net/LRYaq/
<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Kiran Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script>
$(document).ready(function(){
 
 $("#txt").keyup(function(){
   $("#btn").click();
 });

 $("#btn").click(function(){
   alert("button is click event fired");
 });
 
 
});
</script>

</head>

<body>

<input type="button" id="btn" value="button click">

<input type="text" id="txt">

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Gurvinder Pal Singh
Gurvinder Pal Singh
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gaurih
gaurih

ASKER

in the above code snippet, if the button has onclick event as below
<input type="button" id="btn" value="button click" onclick="submitForm()">

Is that possible to trigger the click from the script and as well as the onclick event?
Yes it is possible.

Look at below code. First check function is called then click event is fired.


<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Kiran Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript"></script>
  <script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.js"></script>
<script>
$(document).ready(function(){
 
 $("#txt").keyup(function(){
   $("#btn").click();
 });

 $("#btn").click(function(){
   alert("button is click event fired");
 });
 
 
});

function check()
{
  alert("DD");
}
</script>

</head>

<body>

<input type="button" id="btn" value="button click" onclick="check()">

<input type="text" id="txt">

</body>
</html>

Open in new window

OR

If you want to call submitForm() method you can call it within jquery click event as well like below

 $("#btn").click(function(){
   alert("button is click event fired");
  submitForm();
 });

So that click event is fired as well as submitForm is called.
Avatar of gaurih

ASKER

Hi guruvinder,
I tried your sample code, onclick event is removed but alert is not coming for me included in .bind function. am I missing something?
please show that code to me

are you placing the code in document.ready or outside?