Solved

click jquery button from another click

Posted on 2014-01-23
13
746 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
[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: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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
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 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: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 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: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 53

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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)
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…

739 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