Solved

click jquery button from another click

Posted on 2014-01-23
13
714 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JDeveloper 12c for 32 bit 4 34
jQuery Scroll on Mobile devices 1 22
Javascript - output csv file 18 19
ajax form sumbit 3 25
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 …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now