Javascript to disable button and show <div> text

Experts,

I'd like to disable a button which posts a form and show the text within a div tag (hide it at the start) with the text showing please wait.

Alternatively here is my code for the button so far which I would like to change the text to please wait...

Ive tried this already, but the text didnt change;

<input type='submit' name='Submit' value='Get quote now' onclick='this.disabled=true;document.form1.submit();'>

My colleague gave me this, but it doesnt work;

<input type="submit" name="Submit" value="Get quote now" onclick='this.value = "Please wait..."; this.disabled = true; this.form.submit();'>
mhouldridgeAsked:
Who is Participating?
 
BadotzConnect With a Mentor Commented:
<$.02>
>>What is the problem with your code.

It is ugly and extremely hard to debug.

Put your code in a function outside of the HTML - the <head> section is a good place.

Don't forget to enable your button after the form submits.
</$.02>
...
<head>
<script type="text/javascript">
function check_submit(btn, frm)
{
    btn.disabled = true;
    btn.value = 'Please wait...';
    frm.submit();
    return true;
}
</script>
...
</head>
<body>
...
<input type='submit' name='Submit' value='Get quote now' onclick='return check_submit(this, document.form1);'>
...

Open in new window

0
 
gops1Commented:
What is the problem with your code. Only thing you did not add the changed text

<input type='submit' name='Submit' value='Get quote now' onclick=''this.value = "Please wait..."; this.disabled=true;document.form1.submit();'>
0
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
I would suggest this...

Not a great idea to disable the submit button


<script>
function doIt(theBut) {
  var msg = 'Please wait...';
  if (theBut.value==msg) return;
 
  theBut value=msg; 
  theBut.disabled = true; 
  theBut.form.submit();'
}
document.write('<input type="button" value="Get quote now" onclick="doIt(this)">')
</script>
<noscript>
<input type="submit" name="Submit" value="Get quote now">
</noscript>

Open in new window

0
 
BadotzCommented:
Who was that Masked Man...?
0
 
Computer101Commented:
Forced accept.

Computer101
Community Support Moderator
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.