Solved

click jquery button from another click

Posted on 2014-01-23
13
740 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:sevensnake77
  • 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:sevensnake77
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
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 58

Expert Comment

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

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

Author Comment

by:sevensnake77
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 52

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:sevensnake77
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 52

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:sevensnake77
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:sevensnake77
ID: 39806755
Here is the example on jfiddle
http://jsfiddle.net/qhdQY/38/
0
 
LVL 52

Accepted Solution

by:
Scott Fell,  EE MVE earned 500 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:sevensnake77
ID: 39806943
tks
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Requirements JQuery 1.6+ HTML CSS Introduction This article was inspired by an EE question (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28372511.html) on how to make a page show some balloons animate up a page…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

821 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