Link to home
Start Free TrialLog in
Avatar of byteslinger
byteslinger

asked on

How can I get this to work with a submit button?

I have several functions that are operating off a submit button, but basically I need this one to work, and it doesn't seem to like anything but an "input type='button'"  

Is there any way to make it work with a button type of "submit"???


<html>
<head>
<style>
.button2     { border:outset 2px; font-size:11px; background:#FAE6BF; color:blue;}
</style>

<script language="javascript">
var time_now = new Date();
function blink_the_buttons(){
     temp_now = new Date();
     check = temp_now - time_now;
     for (i=0;i<blink_buttons.length;i++){
          if ((blink_buttons[i][2] * blink_buttons[i][3]) < check){
               obj = eval(blink_buttons[i][0]);
               blink_buttons[i][3] = blink_buttons[i][3] + 1;
               if (blink_buttons[i][4] == true){
                    obj.value = "";
                    blink_buttons[i][4] = false;
               } else {
                    obj.value = blink_buttons[i][1];
                    blink_buttons[i][4] = true;
               }
          }
     }
setTimeout("blink_the_buttons()",0);
}

</script>
</head>
<body>
<form name=myform>
<input class="button2" type=button value="Second blinking text" name=processing style="width:150;" onclick="blink_the_buttons();">
</form>
</body>
</html>

<script language="javascript">
var blink_buttons = new Array();
blink_buttons[0] = new Array(document.myform.processing,"Second blinking text",400,0,true);
</script>
Avatar of voldo37
voldo37

Put the call to the function in the onSubmit event of the form.  You will also need to return false from the function to prevent the form from submitting which kind of defeats the purpose of the submit button.

setTimeout("blink_the_buttons()",0);
return false;
}

<form name=myform onsubmit="return blink_the_buttons();">

Avatar of byteslinger

ASKER

so you're saying there's no way to pass data and still have the button blink?

the reason I want this to work is because the submission process can take several seconds, and I want to use this method to inform the user that something's happening.
So you want to blink while the submit is getting it's act in gear? In otherwords, you *do* want to submit, but there's a delay.


function blink_the_buttons(f){
// code for blink_the_buttons
   f.submit();
}

with
<form name="myform">
<input class="button2" type=button value="Second blinking text" name=processing style="width:150;" onclick="blink_the_buttons(this.form);">
</form>

OR

function blink_the_buttons(){
// code for blink_the_buttons
   return true;
}
 with
<form name=myform onsubmit="return blink_the_buttons()">
<input class="button2" type=submit value="Second blinking text" name=processing style="width:150;" >
</form>
ASKER CERTIFIED SOLUTION
Avatar of miskate
miskate

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Perfect! Thanks for the hint! Here's the finished product (sort of)

<html>
<head><title></title>
<style>
.button2     { border:outset 2px; font-size:11px; background:#FAE6BF; color:blue;}
</style>

<script language="javascript">
<!--
var time_now = new Date();
function blinkIt(){
     temp_now = new Date();
     check = temp_now - time_now;
     for (i=0;i<blink_buttons.length;i++){
          if ((blink_buttons[i][2] * blink_buttons[i][3]) < check){
               obj = eval(blink_buttons[i][0]);
               blink_buttons[i][3] = blink_buttons[i][3] + 1;
               if (blink_buttons[i][4] == true){
                    obj.value = "";
                    blink_buttons[i][4] = false;
               } else {
                    obj.value = blink_buttons[i][1];
                    blink_buttons[i][4] = true;
               }
          }
     }
setTimeout("blinkIt()",0);
}
function mysubmit(f) {
     f.submit();
     blinkIt();
}
//-->
</script>
</head>
<body>

<form name=myform action="http://bigslowpage.com">
<input class="button2" type="button" value="Submit" name=processing style="width:150;" onclick="mysubmit(this.form);">
</form>

<script language="javascript">
var blink_buttons = new Array();
blink_buttons[0] = new Array(document.myform.processing,"Submitting...",500,0,true);
</script>

</body>
</html>