Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript to disable button and show <div> text

Posted on 2007-11-23
7
Medium Priority
?
2,121 Views
Last Modified: 2008-02-20
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();'>
0
Comment
Question by:mhouldridge
[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
7 Comments
 
LVL 17

Expert Comment

by:gops1
ID: 20339050
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
 
LVL 29

Accepted Solution

by:
Badotz earned 1000 total points
ID: 20339197
<$.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
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 1000 total points
ID: 20339412
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
 
LVL 29

Expert Comment

by:Badotz
ID: 20643381
Who was that Masked Man...?
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20943723
Forced accept.

Computer101
Community Support Moderator
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

618 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