Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

click jquery button from another click

Posted on 2014-01-23
13
Medium Priority
?
782 Views
Last Modified: 2014-01-24
what I am trying to do is click a button event that that clicks another button to open up the popup. this will later if so initiate a function on post. But right now I can get one with out the other working but not together.

 $(document).ready(function () {
  
         $(function () {

             $("a").click(function () {
                 if ($(this).val && $(this).attr("id")) {
                     $("#lnkDialog").click({
                         'buttons' : {
                             'OK': {
                                 click: function () {
                                    alert(this.id);
                                 }
                             },
                             'Cancel': {
                                 click: function () {
                                    'close popup'
                                 }
                             }
                         }
                     });
                
                 }

             });
         });
      });


 // Hiden button<a href="#popupDialog"   data-transition="pop" id='lnkDialog' data-inline="true"  data-position-to="origin" data-rel="popup"  data-iconshadow="true"  aria-haspopup="true" aria-owns="#popupDialog" style='display:none;'></a> 


button initial jquery //// <a href="#" id="34" >click1</a>



///Pop up message
<div data-role="popup" id="popupDialog" data-overlay-theme="a" data-theme="c" style="max-width:400px;" class="ui-corner-all">
			<div data-role="header" data-theme="a" class="ui-corner-top">
				<h1>demo</h1>
			</div>
			<div data-role="content" data-theme="d" class="ui-corner-bottom ui-content">
				<h3 class="ui-title">Are you sure?</h3>
				
				<a href="#" data-role="button" data-inline="true" data-rel="back" data-theme="c">Cancel</a>    
				<a href="#" data-role="button" data-inline="true" data-rel="back" data-transition="flow"  data-theme="b">Yes</a>  
			</div>
		</div>

Open in new window



Have the example up on JSfiddle
http://jsfiddle.net/qhdQY/


Here is the second example by itself that works. without  initiating the next button.
http://jsfiddle.net/qhdQY/4/
0
Comment
Question by:Seven price
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 3
  • +1
13 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39804785
you can prgramatically click on a button (or anything clickable) with $("selector").trigger("click") or just $("selector")click()
0
 
LVL 9

Author Comment

by:Seven price
ID: 39804873
does not seem to work.
http://jsfiddle.net/qhdQY/7/
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39804894
if you click directly on the link do it work? no, so why should it work programatically ?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 58

Expert Comment

by:Gary
ID: 39804991
$("lnkDialog").trigger("click")

should b
 $("#lnkDialog").trigger("click")
0
 
LVL 9

Author Comment

by:Seven price
ID: 39805080
Because this is not a programatically problem, its a client side. problem.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39805086
Javascript is client side
Javascript is << programatically >>
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39805841
Do you mean you want the pop up to open without clicking something?  You would use the open method http://api.jquerymobile.com/popup/#method-open

http://jsfiddle.net/q2LpW/3/
  
$(function () {
   $("#popupDialog").popup("open")
});

Open in new window

In your jsfiddle you have document ready function nested.

This $(document).ready(function () { and this $(function () { are the same.  You also need to specify $("lnkDialog").trigger("click") a class or $(".lnkDialog").trigger("click") id $("#lnkDialog").trigger("click")
$(document).ready(function () {
  
         $(function () {

             $("a").click(function () {
                 if ($(this).val && $(this).attr("id")) {
                     $("lnkDialog").trigger("click")
                    
                
                 }

             });

      });

Open in new window

0
 
LVL 9

Author Comment

by:Seven price
ID: 39806594
 $(document).ready(function () {
  
         $(function () {

             $("a").click(function () {
                  if ($(this).val && $(this).attr("id")) {
 
                   //  $("#lnkDialog").click();
               alert(this.id);
                   $("#popupDialog").popup("open")
                     var BatchId = this.id
                    

                 }

             });
         });
      });

Open in new window


Ok this way seems to work better. but can I control the function from cancel to yes>?
0
 
LVL 53

Expert Comment

by:Scott Fell, EE MVE
ID: 39806611
>I control the function from cancel to yes>?

I don't follow what you are asking

Also, you don't need both lines.   One or the other.
$(document).ready(function () {
 
         $(function () {
0
 
LVL 9

Author Comment

by:Seven price
ID: 39806731
Cancel and ok.  When I click nothing happens
("#popupDialog").popup("open", { dismissible: false })({
                                  'position': 'original',
                                  'buttons': {
                                      'Ok': {
                                          click: function () {
                                              alert(this.id);
                                          }
                                      },
                                      'Cancel': {
                                          click: function () {
                                              alert("Cancel");
                                          }
                                      }
                                  }

                      });

Open in new window

0
 
LVL 9

Author Comment

by:Seven price
ID: 39806755
Here is the example on jfiddle
http://jsfiddle.net/qhdQY/38/
0
 
LVL 53

Accepted Solution

by:
Scott Fell,  EE MVE earned 2000 total points
ID: 39806883
Add some id's to the html of the a links that form the faux buttons and put a click function on each http://jsbin.com/upEFAdU/1/edit
$(function () {

  $("a#btnCancel").click(function () {
    alert("Cancel");
  });
  
  $("a#btnLock").click(function () {
     alert("Lock");
  });
  
    $("a#34").click(function () {
        if ($(this).val && $(this).attr("id")) {


            $("#popupDialog").popup("open", {
                dismissible: false
            })({
                'position': 'original'
                

            });

        }

    });
});

Open in new window

0
 
LVL 9

Author Closing Comment

by:Seven price
ID: 39806943
tks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

662 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