[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

call the onclick event inside the input type=submit

Posted on 2011-10-20
7
Medium Priority
?
330 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:gaurih
  • 3
  • 2
  • 2
7 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37004787
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

0
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 37004803
check this one on submit button
http://jsfiddle.net/gurvinder372/jseF4/
0
 

Author Comment

by:gaurih
ID: 37004804
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?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37004834
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

0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37004839
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.
0
 

Author Comment

by:gaurih
ID: 37004843
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?
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 37004850
please show that code to me

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Will the future of mobile app development include the same trends as those most relevant today? Find out by checking out the 7 trends of the future.
LinkedIn blogging is great for networking, building up an audience, and expanding your influence as well. However, if you want to achieve these results, you need to work really hard to make your post worth liking and sharing. Here are 4 tips that ca…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question