# Web form checkbox from VBA



## bluphoto (Aug 15, 2009)

I have a webform (of which I am a customer) which has 30 checkboxes on it. I want to programmatically check particular checkboxes depending on the values in excel.

I know how to open the page in IE and retrieve the source code to an excel spreadsheet.

My problem is that all the checkboxes seem to be named "friends[]", and I guess clicking them just assigns an element to that array.

So I either need to programmatically check the required checkboxes, or programmatically populate the friends array, and then programmatically "click" the "delete selected friends" button.

Any assistance would be greatly appreciated.

Here are a few lines from the page which might help...

In Header...

```
<FORM method=post action=/mystuff/friends/action_delete_friends/>
<INPUT value=366176 type=hidden name=id> 
<INPUT value=deletemultiple type=hidden name=action> 
<INPUT value="Delete Selected Friends" type=submit name=submit>
```

A couple of the checkboxes...

```
<TD><INPUT value=191111 type=checkbox name=friends[]> </TD>
<TD><INPUT value=369784 type=checkbox name=friends[]> </TD>
<TD><INPUT value=467906 type=checkbox name=friends[]> </TD>
```


----------



## Laxer (Dec 28, 2010)

I would handle it with javascript....

I will let the thread sit here in MS for a bit, if not one here can solve it I will move it down to Design....

I can do the web portion if someone can get the information out of excel we can piece it together and get it to work....

*Note:* Check boxes will have values like friends[0],friends[1] respective to their location on the webpage once I code that portion up :grin:


----------



## bluphoto (Aug 15, 2009)

Javascript? Where exactly would that javascript be running? I thought javascript had to be running in a browser... and I don't have administrfative access to this form - only as a user.

I assume you mean the checkboxes will have NAMES like friends[1], rather than values... As you can see the VALUES are numbers like "191111".

Are you saying that I can put some javascript in excel, embedded in VBA, which can work on the form parameters in the browser?

How can a checkbox have a "value" other than checked or unchecked, and how is each checkbox identified? Depending on how the page is sorted, the checkbox with value "191111" might come first or thirtieth, or anywhere inbetween.

How, for example, can I programatically check the box which has value "191111", wherever it might appear on the page?

Is it easier just to populate the "friends" array independant of the checkboxes?


----------



## Laxer (Dec 28, 2010)

Sorry, yes I meant Names not values....

Also, Sorry I thought you wanted to go Excel -> browser not vise-versa....

Anyway... If you name the boxes like so:

```
<TD><INPUT value=191111 type=checkbox name=friends[0]> </TD>
<TD><INPUT value=369784 type=checkbox name=friends[1]> </TD>
<TD><INPUT value=467906 type=checkbox name=friends[2]> </TD>
```
From there you should be able to snag it with whatever language you are using....

Here is an example with PHP(because I am most familiar with it):

```
$value=$_POST['friends'];
//From here its just an array:
echo $value[0];
echo $value[1];
```



> How, for example, can I programatically check the box which has value "191111", wherever it might appear on the page?


Automatically check the boxes in excel or on the webpage?

Excel -> Macros
Web -> Javascript/modified file before hand


----------



## bluphoto (Aug 15, 2009)

No, you were right the first time, I am going from Excel TO the browser. I have a list of "values" in excel, for which I want to "check" the corresponding checkbox in the browser. My problem is identifying the correct checkbox to check as all checkbox names are referred to simply as "friends[]" with no array element number. I am unable to do anything with the web code so I can't do as you suggest with the checkbox names. (I have just shown the existing code above from the "view source" window).

The only language I am therefore able to use is VBA. You mention using javascript in your first reply, but I couldn't work out where that javascript would be run (surely not in the excel VBA environment, and obviously not in the web code as it's not my web page)


----------

