473,320 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

button question

Hi, could anyone please tell me how to make a button look like "being clicked"?
A button picture always looks static, though a link is associated with it.
Thank you.
Jul 23 '05 #1
7 2570
Yaqian Fang wrote on 07 nov 2004 in comp.lang.javascript:
Hi, could anyone please tell me how to make a button look like "being
clicked"? A button picture always looks static, though a link is
associated with it. Thank you.


<button onclick="this.style.color='red'">
click me and stay red</button>

<button onclick="this.disabled=true">
click me once only</button>
<button onclick="this.style.borderStyle='inset';this.disab led=true">
depress me once only</button>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #2
Yaqian Fang wrote:
Hi, could anyone please tell me how to make a button look like "being clicked"?
A button picture always looks static, though a link is associated with it.
Thank you.


Create a "clicked" image and onmousedown change to it. onmouseup change
back.

Fred.
Jul 23 '05 #3
Evertjan. wrote:
Yaqian Fang wrote on 07 nov 2004 in comp.lang.javascript:
Hi, could anyone please tell me how to make a button look like "being
clicked"? A button picture always looks static, though a link is
associated with it. Thank you.


<button onclick="this.style.color='red'">
click me and stay red</button>

<button onclick="this.disabled=true">
click me once only</button>

<button onclick="this.style.borderStyle='inset';this.disab led=true">
depress me once only</button>


Evertjan,

very nice examples. I added a bit of code to the 2nd one:

<button onclick="this.disabled=true;this.value='Please Wait...';">click
me once only</button>

Mike
Jul 23 '05 #4
mscir wrote on 07 nov 2004 in comp.lang.javascript:
very nice examples. I added a bit of code to the 2nd one:

<button onclick="this.disabled=true;this.value='Please Wait...';">click
me once only</button>


Nice idea!

This does work, but it should not, me thinks(...?)
innerHTML seems the way to go.

<button
onclick="this.disabled=true;this.innerHTML='Please Wait...';">
click me once only</button>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #5
Evertjan. wrote:
mscir wrote on 07 nov 2004 in comp.lang.javascript:
very nice examples. I added a bit of code to the 2nd one:

<button onclick="this.disabled=true;this.value='Please Wait...';">click
me once only</button>


Nice idea!

This does work, but it should not, me thinks(...?)
innerHTML seems the way to go.

<button
onclick="this.disabled=true;this.innerHTML='Please Wait...';">
click me once only</button>


Good point, I found this with google... it discusses both approaches and
their potential problems, and has code to handle more than one browser:

http://www.permadi.com/tutorial/jsInnerHTMLDOM/

Here's an example using that code, it works on my IE 6, Netscape 7.2,
Moz 1.7.3, Firefox 1.0 pr:

<script type="text/javascript">
function replaceButtonText(buttonId, text){
if (document.getElementById) {
var button=document.getElementById(buttonId);
if (button) {
if (button.childNodes[0]) {
button.childNodes[0].nodeValue=text;
} else if (button.value) {
button.value=text;
} else { //if (button.innerHTML)
button.innerHTML=text;
}
}
}
}
</script>

<button id="b1" onclick="replaceButtonText('b1', 'Please Wait
1...');">click me once only</button>
<br>
<button id="b2" onclick="replaceButtonText('b2', 'Please Wait
2...');">click me once only</button>

Mike
Jul 23 '05 #6
Thank you all very much!

mscir wrote on 07 nov 2004 in comp.lang.javascript:
very nice examples. I added a bit of code to the 2nd one:

<button onclick="this.disabled=true;this.value='Please Wait...';">click
me once only</button>


Nice idea!

This does work, but it should not, me thinks(...?)
innerHTML seems the way to go.

<button
onclick="this.disabled=true;this.innerHTML='Pleas e Wait...';">
click me once only</button>

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress,
but let us keep the discussions in the newsgroup)

Jul 23 '05 #7
mscir wrote:
<snip>
<script type="text/javascript">
function replaceButtonText(buttonId, text){
if (document.getElementById) {
var button=document.getElementById(buttonId);
if (button) {
if (button.childNodes[0]) {
button.childNodes[0].nodeValue=text;
} else if (button.value) {
button.value=text;
} else { //if (button.innerHTML)
button.innerHTML=text;
}
}
}
}
</script>

<button id="b1" onclick="replaceButtonText('b1', 'Please Wait
1...');">click me once only</button>


This might work on more browsers, if support for "this" is better than
for getElementById.

function replaceButtonText(btn, text){
//alert('btn.childNodes[0] '+btn.childNodes[0]+'\nbtn.value
'+btn.value+'\nbtn.innerHTML '+btn.innerHTML);
if (btn.childNodes[0]) {
btn.childNodes[0].nodeValue=text;
} else if (btn.value) {
btn.value=text;
} else { //if (button.innerHTML)
btn.innerHTML=text;
}
}

<button id="b1" onclick="replaceButtonText(this, 'Please Wait
....');">click me once only</button>

Mike
Jul 23 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
2
by: ziggs | last post by:
I have a form that has three text boxes and a command button. For textbox1, I can tab to the next field and enter into that field. If I hit the enter button while I'm in the textbox1 field, it...
2
by: Kevin Blackwell | last post by:
Probably a simple question, but how do I either have a button that is not clickable. I don't want the visual clicking action to the button. Or is there a way to raise so other type of object so...
0
by: VB Programmer | last post by:
I followed this article on creating a rollover button for ASP.NET: http://aspnet.4guysfromrolla.com/articles/091703-1.aspx Question: When I click on the button I would like code-behind to run. ...
7
by: nathaniel.k.lee | last post by:
Is it not possible, in IE, to dynamically click a radio button? I'm grabbing some values from a database and using them to populate radio buttons on a page. I have alternate code for Firefox...
7
by: David T. Ashley | last post by:
Hi, For a web page, I want a SUBMIT button that commits the form data and a CANCEL button that goes to a different target (i.e. a different script). I haven't figured out how to do this,...
0
by: Rudy | last post by:
Hello all! I have a quick question. Imported a .gif file that is oval shape for a button, looks great! But when a mouse goes over the button, the outline of the button pops up in a diffrent...
0
by: Kevin Blount | last post by:
I need to create a page that lists a users Content, and allow them to add subscribers to or remove subscribers from that Content. The list may contain just one Content item, but it could just as...
2
by: MASREMIND | last post by:
Hi,I'm new on this forum,and I'm new i ASP.net, so I've got question: is it possible in ASP to click on button or to click on LinkButton and when button is clicked on other page program build ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.