Solved

Need to combine JavaScript funtions from 2 buttons

Posted on 2014-07-24
6
230 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

617 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