Skip to main content
Participant
September 23, 2021
Question

Checkbox checked, disabled it

  • September 23, 2021
  • 3 replies
  • 1406 views

Please, will you help me?

I need disable a checkbox with javascript after it has been selected, I did the next :

 

I selected a rows from Postgres DB for create the checkbox. I use a Perl languaje in Linux Centos 7, the code is next:

 

while(my $ref_alarm = $sth->fetchrow_hashref()) {

        ($gabinete)=$ref_alarm->{'gabinete'};

        ($alarma)=$ref_alarm->{'descrip_alarma'};

        print "<input type='checkbox' name='alarma' id='alarma' value='$alarma' onclick='alarma_reg(this.value);'/>$alarma</input>";

        print "<br>";

}

 

I had been use javascript for disable the checkbox that had been selected:

 

function alarma_reg(p_alarma) {

                //Get the checkbox

                document.getElementById("p_alarma").disabled = true;

                alarma_operada+=p_alarma + ',';

                document.getElementById("ver_alarmas").value=alarma_operada;

        }

 

But the option selected is not disable, please could you help me?

 

Regards

Xochitl

This topic has been closed for replies.

3 replies

JR Boulay
Community Expert
Community Expert
September 24, 2021

Your script is not a regular PDF-JavaScript.

Place this script in the checkbox as a MouseUp action:

 

if (event.target.value) != "Off") {event.target.readonly = true;}

Acrobate du PDF, InDesigner et Photoshopographe
Participant
September 24, 2021

Thanks for answered but sorry I don't what is a PDF-JavaScript.

 

Sorry.

Regards

Bernd Alheit
Community Expert
Community Expert
September 24, 2021

Does you use a HTML form?

Participant
September 24, 2021

Yes.  I had been use a HTML FORM.

Bernd Alheit
Community Expert
Community Expert
September 25, 2021

You are posting in a wrong forum.

Inspiring
September 24, 2021

You want it to be 'readonly' if it's checked?

How do you check it, manually or with a code from somewhere else?

Do you have condition to uncheck it?

Participant
September 24, 2021

You want it to be 'readonly' if it's checked?

Yes, when the user check the checkbox it's state must to change to disable o readonly.

 

How do you check it, manually or with a code from somewhere else?

I checked manually

 

Do you have condition to uncheck it?

The condition is, when it's selected  then change the checkbox state to disable.  So, the user will can't select anymore.