Solved

Need to combine JavaScript funtions from 2 buttons

Posted on 2014-07-24
6
227 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Bootstrap question 4 26
Echo'd values in dropdowns 6 27
Table style position to the left 8 24
web page freezes after ajax post 7 41
Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
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…

679 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