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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Disabling a button after onClick 2

Status
Not open for further replies.

AnnIsabelle

Programmer
Apr 10, 2001
9
BE
I send the following question to the html-forum and they said to ask here:

Hi,
I'm making a form with a button on it. The button has an onClick-event that calls a function. After the first time the user has clicked the button,I want to disable it. This way the user can only click once. I need this because the function I call checks the answer given by the user and, if correct, increases a score. Now the user can click an indefinite number of times and augment the score.

Thanks,
AnnIsabelle

>An answer from MikeBarone (Programmer) Apr 12, 2001
>I have seen it done using a toggle variable. After it is >clicked once it changed the onclick event to onblur whick >keeps them from clicking it again.

>You can get the actual code from JavaScript pros over at >that forum.

 
Give the button a name, and then just say this:

document.buttonName.disabled = true;

as the last line in your onClick function for that button.

Should fix you right up!

:)
Paul Prewett
 
Hi,

I'm trying to do something like this also...I want to disable radio button "A" when radio button "B" is clicked.

This is what I have so far...it doesnt work. Why? IE5.

function dis_mmedia(){
document.form1.A.disabled = true;
}

function ena_mmedia(){
document.form1.A.disabled = false;
}

<input type=radio name=B onClick=&quot;ena_mmedia()&quot;>
<input type=radio name=B onClick=&quot;dis_mmedia()&quot;>
 
look at this:

<input type=&quot;radio&quot; name=&quot;group1&quot; id=&quot;a&quot; onclick=&quot;b.disabled=true&quot;>
<input type=&quot;radio&quot; id=&quot;b&quot; name=&quot;group1&quot; onclick=&quot;a.disabled=true&quot;> jared@eae.net -
 
Thanks for the help: both solutions work!!

Only one remark for link9: there was a mistake in the object model

document.buttonName.disabled = true;
should be
document.formName.buttonName.disabled = true;

Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top