Solved

click jquery button from another click

Posted on 2014-01-23
13
737 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

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