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

x
?
Solved

Need to combine JavaScript funtions from 2 buttons

Posted on 2014-07-24
6
Medium Priority
?
233 Views
Last Modified: 2014-07-25
Hi,
How can I combine JavaScript functions from 2 buttons?

<input name="Submit" type="submit" onclick="javascript:window.print()" value="Print Details" />

<input type="button" class="button green" onClick="if(checkFields()){location.href='process_payment.php?cartId=<?php echo $cookie;?>'}" value="Process Order" >

Open in new window



I would like my print button to have an alert "please note that the order details have not been processed yet, do you want to process this order now?"

and if they click ok then execute  "if(checkFields()){location.href='process_payment.php?cartId=<?php echo $cookie;?>'}"



I was also wondering if it is better to move location.href='process_payment.php?cartId=<?php echo $cookie;?> to the checkFields function and can I add an animated gif to this function?

<script language="JavaScript" type="text/javascript" >
   //<!--
  var clickcount = 0;

   function checkFields(){
     if (clickcount == 0) {
       //count clicks 
       clickcount ++;
       return true;
     }
     else {
       alert("Transaction already in progress.. Please wait...");
       return false;
     }
   }
   //-->

</script>

Open in new window

0
Comment
Question by:sabecs
[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
  • 3
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 1600 total points
ID: 40218601
What do you mean by animated gif.
Please elaborate little more for that

<script language="JavaScript" type="text/javascript" >
   //<!--
  var clickcount = 0;

   function checkFields(cookie){


var r = confirm("please note that the order details have not been processed yet, do you want to process this order now?");
if (r == true) {
    location.href='http://lovetomarry.com/process_payment?cartId='+cookie;

} else {
    //return false;
} 

  
   }
</script>
  <a href="javascript:checkFields('cookie')">Test</a>

Open in new window

0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 400 total points
ID: 40219191
<input name="Submit" type="button" id="PrintDetails" value="Print Details" />

<input type="button" class="button green" id="ProcessOrder" value="Process Order" data-cartid="<?php echo $cookie;?>"  />

Open in new window


window.onload = function() {
    document.getElementById("PrintDetails").onclick = function() {
          var ok = window.confirm("please note that the order details have not been processed yet, do you want to process this order now?");
          if(ok) {
              var done = processOrder();
              if(done) {
                  document.getElementsByTagName("form")[0].submit();
              }
          }
          else {
              window.print();
              document.getElementsByTagName("form")[0].submit();
          }
    }
    var processOrder = function() {
            var cart =  this.getAttribute("data-cartid").value;
            if(checkFields()) {
                location.href = 'process_payment.php?cartId=' + cart;
            }
    }
    document.getElementById("ProcessOrder").onclick = processOrder;
}

Open in new window

0
 

Author Comment

by:sabecs
ID: 40219588
Thanks fro your comments..

Regarding the animated gif, just wondering if there is a wait to display a message that the order is in progress which may take 10-20 seconds, I was wondering if I can display a div with an animated image inside it  via a function?
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 15

Accepted Solution

by:
Insoftservice earned 1600 total points
ID: 40220041
Its little css and jquery work.

Just add line in my comments


   function checkFields(cookie){

    document.getElementById('loader').display="block";
var r = confirm("please note that the order details have not been processed yet, do you want to process this order now?");
if (r == true) {

....
}else{
....
}
document.getElementById('loader').display="none";
}

Html part

<div id="loader" style="display:none;position:absolute;top:0%;left:0%;width:100%;height:2500px;background-color:#EFEAEA;z-index:1001;-moz-opacity:0.8;opacity:.80;filter:alpha(opacity=80);">
        <table style="margin-top:300px" width="789" border="0" align="center" cellpadding="0" cellspacing="0">
            <tr><td width="763" align="center" valign="top"><img src="loading.gif" border="0" /></td></tr>
        </table>
    </div>
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40220078
so you change location(url) of the page and during this order process you want to display a GIF.
if the GIF and Javascript is in the page and you change location of the page how this can be possible?
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 40220199
@leakim971 i think he wants loader image till his clients click ok or cancel button.
@sabecs Please correct me if i am wrong
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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 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…

715 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