Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cURL(y) JS disable button on submit? 1

Status
Not open for further replies.

gdbsti

Technical User
Jul 15, 2003
29
US
Greetings all,
I have .php CC submission page that I'm having problems implementing the Java disable button on submit. I've spent a lot of time trying different methods but am struggling to come up with one that works!
The page submits to auth.net using cURL for same page error responses. Here's the original script stripped back again.(Please forgive me for the screeds of script, but I though I may as well include it now instead of after replies!)
Code:
<head>
<script language=&quot;JavaScript&quot;>
<!--
//this concats the two drop menus into one date variable suitable
//set formName, selectBoxMonth, selectBoxYear and hiddenField to the form name and the input names--!>
function dateFunction() { date1=document.form1.month_menu.options[document.form1.month_menu.selectedIndex].value; date2=document.form1.year_menu.options[document.form1.year_menu.selectedIndex].value; document.form1.x_Exp_Date.value = date1+'-'+date2; }

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!=&quot;&quot;) {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('Credit card number is required');
  document.MM_returnValue = (errors == '');
}

<!--//this concats the two drop menus into one date variable
//set formName, selectBoxMonth, selectBoxYear and--!> hiddenField to the form name and the input names
function dateFunction() { date1=document.form1.month_menu.options[document.form1.month_menu.selectedIndex].value; date2=document.form1.year_menu.options[document.form1.year_menu.selectedIndex].value; document.form1.expiration_date.value = date1+'-'+date2; }
</script>

</head>

<body>
<form name=&quot;form1&quot; method=&quot;post&quot; action=&quot;ecom.php&quot; onSubmit=&quot;dateFunction();&quot;>
<input type=&quot;submit&quot; name=&quot;complete_transaction&quot; value=&quot;Complete Transaction&quot; onClick=&quot;MM_validateForm('x_Card_Num','','RisNum');return document.MM_returnValue&quot;>
</form>
</body>

Any pointers, clues or input would be greatly appreciated!
TIA
Bryce

 
I can't quite grasp what you need from your description but..

I think that you have two competing functions when the form is submitted. In your form tag you have mit=&quot;dateFunction();&quot;> and in your submit button you have onClick=&quot;MM_validateForm('x_Card_Num','','RisNum');return document.MM_returnValue&quot;

I would suggest that you add your code for the &quot;dateFunction()&quot; to the beginning of the MM_validateForm() function...

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks for your reply mwolf. I'm sorry I wasn't more descriptive about what I wanted to achieve.
The script in my first post does work. What I'm trying to add to the script is a &quot;disable-submit-button when form submitted&quot; function. I tried adding these;
Code:
function Disab (val) {
<head>
if(val==&quot;1&quot;) 
{form1.Submit.disabled=true}

}
</head>

<form name=&quot;form1&quot; method=&quot;POST&quot; action=&quot;<%=MM_editAction%>&quot;onSubmit=&quot;Disab(1)&quot;>
</form>
and
Code:
<BUTTON ID=&quot;purchase&quot; 
    onclick=&quot;javascript:document.getElementById('tuition').disabled=true&quot;>Charge
    My Account!</BUTTON>
Notice the JavaScript statement that disables the button:

  document.getElementById('purchase').disabled = true

and a few other similar codes, but with a lot of trial and a whole lot more error, I couldn't get it to make the disable-button-on submit operate.
I'll make the change to the script you suggested and try re-integrating one of the above codes, as the problem you pointed out in the original code may be creating my problems.
If there's a better method for the disable-submit on form submission, I'm all ears..(or shall I say eyes)..
Thanks
Br
 
There are a few ways to do what you're doing. Here's one

<script>
function validForm(){
//after you check form and it's valid...
document.getElementById(&quot;SubBtn&quot;).disabled = true
return true
}
</script>


<form onSubmit=&quot;return validForm()&quot; name=&quot;myForm&quot;>
<input type=&quot;Submit&quot; id=&quot;SubBtn&quot;>

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

fart.gif
 
Thanks Mwolf,

I'll try working your script in.

Cheers
Br
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top