There is a list of links that each lead to their page. On each landing page there is a form with a bunch of checkboxes. Tell me how to make the necessary checkbox marked on the page in the form.

I pass the GET parameters and can get it from the address bar on the target page, but how can I find the checkbox I need and mark it?

Can somehow find the name ?

Transferred from meta.ru.stackoverflow.com Aug 25 '16 at 11:54 .

This question was originally posted on the discussion forum, support and innovations for the site programmers.

1 answer 1

Suppose you already get a get parameter, for example the link has the following form <a href="/page?checked=notice"> .

There is an element on the landing page:

 <input type="checkbox" name="notice"> 

In this case, the JS code will be as follows:

 function autoCheck(){ var checked = getParameterByName('checked'); //получаем значение get параметра checked if (!checked) return; var target = document.querySelector('input[type="checkbox"][name="'+ checked +'"]'); if (!target) return; target.checked = true; } 
  • And where to write this function? on the checkbox page? - Tru
  • Yes, to the checkbox page - Petr Chalov