Answer the question
In order to leave comments, you need to log in
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
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;
});
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 questionAsk a Question
731 491 924 answers to any question