Link to home
Start Free TrialLog in
Avatar of rjef
rjefFlag for United States of America

asked on

click on checkbox

what is the easiest way to click on the first check box using a script on the attached web page
see attached
Avatar of lenamtl
Flag of Canada image


on click of a button
  	 $('#vehicle').prop( 'checked', true )

Open in new window

see a working example
When you say click are you asking

a) How to click that checkbox with script
b) When that box is clicked how to check all the other checkboxes?

If you want to target the checkbox in the first row then

$('.table-class tr:first-child td.column-id :checkbox').prop({'checked': true});

Open in new window

Working sample here
Avatar of rjef


so how would I run this exactly
On page load you can determine if a checkbox is checked by simply adding checked to the input
<input type="checkbox" name="vehicle" value="Car"   checked   > 

Open in new window

If you want the checkbox to be check only when an action is done then you need to use javascript to add the checked to the input
in my example the user need to click on a button then the checkbox that have the specific ID is selected.

The trigger is the click of a button , this could be anything like click on a table row, a tab ...  
I have update the example so one of the input is checked on page load
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rjef


thanks I realized that after I asked.  I am trying to use a webbrowser control in vb6 to do it.  I final got this to work with your help

WebBrowser1.Navigate2 ("javascript:document.querySelectorAll(""input"")[3].click();")
Avatar of rjef


if it is not to much trouble how would I gotten the 2nd checkbox selected?
$('.table-class tr:eq(1) td.column-id :checkbox').prop({'checked': true});

Open in new window