473,395 Members | 1,774 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,395 software developers and data experts.

Button disables self

Hi,

What's the appropriate js for a button to disable itself once it is
clicked (so that, for example, the user sees that the button has been
clicked and cannot be clicked again).

Is it possible for a button to do it to itself (w/o an absolute
reference), such as onClick="this.disabled=false"? This, btw, does not
work...

Many thanks in advance,

Aaron Fude

Jul 23 '05 #1
9 2732
aa*******@gmail.com wrote:
Hi,

What's the appropriate js for a button to disable itself once it is
clicked (so that, for example, the user sees that the button has been
clicked and cannot be clicked again).

Is it possible for a button to do it to itself (w/o an absolute
reference), such as onClick="this.disabled=false"? This, btw, does not work...

Many thanks in advance,

Aaron Fude


Erm...probably get better results with

onClick="this.disabled=true <------- #;=)

Make sure this is what you really want to do....

Jul 23 '05 #2
Erm...probably get better results with

onClick="this.disabled=true <------- #;=)

Make sure this is what you really want to do....

Hi,

The semicolon helped (thanks), but not everything works. I want 3
things to happen:
1. The button is disabled.
2. The action on the form is changed.
3. The form is submitted.

One more complication is that this is in the context of an html library
and I only have access to the button code so whatever happens has to
happen in the onClick attribute!

Thank you very much in advance,

Aaron Fude

Jul 23 '05 #3
aaronf...@gmail.com wrote:
Erm...probably get better results with

onClick="this.disabled=true <------- #;=)

Make sure this is what you really want to do....

Hi,

The semicolon helped [...].


Lol.

Aaron...

This is an..."arrow" <-------

....and this is called...mmm...a "smiley" -------> #;=)

That wasn't actual HTML #:=D

You were setting the 'disabled' property to *false*, which does exactly
the opposite of what you wanted. Sorry for the confusion.

I want 3 things to happen:
1. The button is disabled.
2. The action on the form is changed.
3. The form is submitted.

One more complication is that this is in the context of an html library and I only have access to the button code so whatever happens has to
happen in the onClick attribute!

Thank you very much in advance,

Aaron Fude


<input
type="button"
name="doIt"
value="OK"
onclick="
this.form.action='new_url';
this.form.submit();
this.disabled=true;">

Jul 23 '05 #4
wrote on 25 apr 2005 in comp.lang.javascript:
I want 3
things to happen:
1. The button is disabled.
2. The action on the form is changed.
3. The form is submitted.


<form target='_blank'>
<input name=myVal>
<input type=button value='click me please'
onclick='return myClick(this)'>
</form>
<script type='text/javascript'>
function myClick(x){
x.form.action='http://myCom.com/';
x.form.submit();
x.disabled=true;
return false;
}
</script>

not tested

the target is necessary to keep the original page

You could write it in the attibute space,
but that does not show nice on usenet:

<form target='_blank'>
<input name=myVal>
<input type=button value='click me please'
onclick='this.form.action='http://myCom.com/';
this.form.submit();this.disabled=true;return false;'>
</form>

Beware of wordwrap!

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #5
Thank you Rob and Evertjan. Everything works now!

A follow up question.

Once the form is submitted, does all js cease to execute? Ideally, what
I would like to do is for the button to also show the number of seconds
that passed since it was clicked. Is that possible?

Thanks!

Jul 23 '05 #6
wrote on 25 apr 2005 in comp.lang.javascript:
Thank you Rob and Evertjan. Everything works now!

A follow up question.

Once the form is submitted, does all js cease to execute? Ideally, what
I would like to do is for the button to also show the number of seconds
that passed since it was clicked. Is that possible?


Sure that can be done.

Why don't you hve a go for it? Programming I mean.

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #7
aa*******@gmail.com wrote:
Thank you Rob and Evertjan. Everything works now!

A follow up question.

Once the form is submitted, does all js cease to execute? Ideally, what
I would like to do is for the button to also show the number of seconds
that passed since it was clicked. Is that possible?

Thanks!


Just a question: if the checkbox is disabled, it can't be successful
and therefore wont be submitted. If it isn't checked, it will not be
successful and wont be submitted.

So if you disable it when it's checked, it is never submitted, the
user can't 'uncheck' it either. How does your server know the
control was checked at all? How annoyed do your users get trying to
uncheck it 'cos they changed their mind, but can't?
--
Zif
Jul 23 '05 #8
Zifud wrote on 26 apr 2005 in comp.lang.javascript:
aa*******@gmail.com wrote:
Thank you Rob and Evertjan. Everything works now!

A follow up question.

Once the form is submitted, does all js cease to execute? Ideally,
what I would like to do is for the button to also show the number of
seconds that passed since it was clicked. Is that possible?

Thanks!
Just a question: if the checkbox is disabled,


What checkbox? We were talking buttons.
it can't be successful
???
and therefore wont be submitted. If it isn't checked, it will not
be successful and wont be submitted.
You cannot submit a checkbox or a button, only a form.

The form needs to be submitted first, as in my code, and only then the
button is disabled

So if you disable it when it's checked, it is never submitted, the
user can't 'uncheck' it either. How does your server know the
control was checked at all?
The server does not n=know anything ablout buttons or checkboxes, it
only gets the names and values submitted by the form submission.
How annoyed do your users get trying to
uncheck it 'cos they changed their mind, but can't?


I won't go into the non-programming-technical part. It was not my OQ.
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #9
How's this? *** I appreciate ALL comments!

function countOnWidget(widget) {
if (widget.id == '')
widget.id = randomString();
countOnWidget_(widget.id, widget.value, 0);
}
function countOnWidget_(widgetid, value, secs) {
widget = document.getElementById(widgetid);
widget.value = value + ' ' + secs;
command = 'countOnWidget_(\"' + widgetid + '\", \"' + value + '\", ' +
(secs + 1) + ')';
setTimeout(command, 1000);
}

function randomString() {
var chars =
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmn opqrstuvwxyz";
var string_length = 8;
var randomstring = 'id';
for (var i=0; i<string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum,rnum+1);
}
return randomstring;
}

Jul 23 '05 #10

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

Similar topics

0
by: Sundown | last post by:
I am trying to create a custom button control for the web that, when clicked, disables and changes the text of itself and a bunch of other controls (in the collection). My goal is to end up with a...
8
by: Lee | last post by:
Hi,I'm trying to have a button that fires a click event only once. What is the best way to do so that after the first button click, any the following clicks will be ignored.
1
by: MattB | last post by:
I want to have a "finalize sale" button that disables it's self immediately when pressed (so they can't hit it twice). I thought putting mybutton.enabled=false in the click event would do it, but I...
5
by: Jon Booth | last post by:
Hi All, I'm trying to create a button that once clicked will disable itself (so as not to be clicked twice) I have the following in my cs Button1.Attributes.Add("onClick","return...
2
by: NishSF | last post by:
Would anyone have any suggestions/javascript code so that if one clicks the Radio Button "Yes" below he has the option of selecting any of the six CheckBox below. If the user clicks on Radio Button...
2
by: dunderhead | last post by:
Hello, I am having a problem with function and class syntax. I have one class (MakePanel1) that creates a button and label. The button-click event of the button is linked to a function...
5
by: crystalattice | last post by:
I'm creating a shelve interface using Tkinter. I have a button that allows the user to modify an existing entry; when the button is clicked, a new TopLevel window appears with Entry boxes holding...
51
AccessIdiot
by: AccessIdiot | last post by:
Hi there, I would like to put a button on my form that enables or unlocks the subform and at the same time disables (locks) the main form until the user is done with the subform. At that point the...
2
by: damonjulian | last post by:
hi ,i created 3 buttons such that if button1 is clicked it will disable button2 ,and clicking button3 will restore state of button2 to normal, to my dismay i find that button2 still responds to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.