Solved

Need to combine JavaScript funtions from 2 buttons

Posted on 2014-07-24
6
225 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
  • 3
  • 2
6 Comments
 
LVL 15

Assisted Solution

by:Insoftservice
Insoftservice earned 400 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 100 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
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 15

Accepted Solution

by:
Insoftservice earned 400 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Javasctipt 2 25
how can i apply an assert arrayEqual function ? 2 26
Javascript_Set_dropdown_value 7 32
Grunt script for Build Process 1 29
This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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…

772 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