How to mark checkbox?

Asked

Viewed 2,983 times

-1

I was wondering which Javascript command I can run on the site to mark the image box without clicking it.

It is necessary to know about box html?

Before:

Afterward

inserir a descrição da imagem aqui

  • take the checkbox id, and mark the checked property as true.

  • example with jquery: http://answall.com/questions/49673/fun%C3%A7ao-para-marcar-desmar-checkbox-jquery

1 answer

1


If you refer to a checkbox, you can do as follows:

HTML example:

<form action="">
<input type="checkbox" id="my_checkbox" value="Bike">Checkbox<br>
</form>

Javascript:

var myCheckbox = document.getElementById('my_checkbox');
myCheckbox.checked = true;

Accessing inside an iframe:

var myFrame = document.getElementById('my_frame');
var myCheckbox = myFrame.contentDocument.getElementById('my_checkbox');
myCheckbox.checked = true;
  • and if this box is inside a frame ?

  • You could do it like this: Document.getElementById( "my_frame" ).contentDocument.getElementById('my_checkbox'). checked = true;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.