S
S
Sergey2015-10-10 02:12:00
JavaScript
Sergey, 2015-10-10 02:12:00

How to pass checkbox selected via link?

Hello, It is
necessary to set the checkbox enabled when we follow a special link from the site.

That is, for example, if you put id="xxx" for an element in the markup and then write
site.ru/page.php#xxx in the link, the browser will automatically transfer to this section

. Is there something similar for checkboxes and radio buttons?
for example site.ru/page.php?select=checkbox1,checkbox2

And after the transition several checkboxes were automatically included.

I would be grateful for help or direction of thought in resolving the issue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vitaly Inchin ☢, 2015-10-10
@dpmango

var chBx = location.search.match(/select=([^&]+)/);

chBx && chBx[1].split(",").forEach(function(id){
  id = document.getElementById(id);
  if(id && id.type == "checkbox") id.checked = true;
});

E
Evgeny Konkin, 2015-10-10
@konnn

Probably you can just write id=check1 for checkboxes, and then specify site.ru/page.php#check1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question