# Read text file and check multiple checkbox

**URL:** <https://www.ruby-forum.com/t/read-text-file-and-check-multiple-checkbox/188920>\
**Category:** Ruby\
**Created:** [May 20, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/read-text-file-and-check-multiple-checkbox/188920 "2010-05-20T15:05:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetzubair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@sweetzubair](https://www.ruby-forum.com/u/sweetzubair)\
**Post date:** [May 20, 2010, 3:05pm UTC](https://www.ruby-forum.com/t/read-text-file-and-check-multiple-checkbox/188920/1 "2010-05-20T15:05:38Z")

</div>

Hi Friends,

```
     I try to check the Multiple Checkboxes in the page.

```

first i read the value in the text file and assing it to the variable.  
but the problem is that at the time only one check box are selected.

textfile values:  
selectedLocationOids=0000025354000000630d  
selectedLocationOids=000002527100000062bc

* * *

HTML Code:

* * *

RUBY Script:  
require ‘watir’  
include Watir  
require ‘logger’

opts = {}  
File.open(“c:/test/Flow1.txt”) do |f|  
f.each\_line do |line|  
opts[$1] = $2 if line =~ /^(._)=(._)$/  
end  
end  
@check\_location = opts[“selectedLocationOids”]  
@check\_location1 = opts[“selectedLocationOids”]

ie.checkbox(:value,@check\_location).set()  
ie.checkbox(:value,@check\_location1).set()

---

<div class="post-metadata">

**Author:** ![sweetzubair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@sweetzubair](https://www.ruby-forum.com/u/sweetzubair)\
**Post date:** [May 20, 2010, 4:13pm UTC](https://www.ruby-forum.com/t/read-text-file-and-check-multiple-checkbox/188920/2 "2010-05-20T16:13:01Z")

</div>

KingMaker KingMaker wrote:

> Hi Friends,
> 
> ```
> I try to check the Multiple Checkboxes in the page.
> 
> ```
> 
> first i read the value in the text file and assing it to the variable.  
> but the problem is that at the time only one check box are selected.
> 
> textfile values:  
> selectedLocationOids=0000025354000000630d  
> selectedLocationOids=000002527100000062bc
> 
> * * *

In the example that you provided it seems that value of @check\_location  
is equal to the value of @check\_location1. Shouldn’t they be different?

---

<div class="post-metadata">

**Author:** ![sweetzubair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@sweetzubair](https://www.ruby-forum.com/u/sweetzubair)\
**Post date:** [May 20, 2010, 5:34pm UTC](https://www.ruby-forum.com/t/read-text-file-and-check-multiple-checkbox/188920/3 "2010-05-20T17:34:27Z")

</div>

On Thu, May 20, 2010 at 8:05 AM, KingMaker KingMaker  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> * * *
> 
> * * *
> 
> end

In addition to what Marcin said:  
\*Your html can’t have two elements with the same ID (ID’s must be  
unique,  
like a social security number)  
\*Your inputs should end with /\> instead of just \> to close the tag.  
\*Since they are checkboxes, they should also have different names. The  
name  
is what determines the name of the key that the server receives, so when  
you  
have two inputs whose names are selectedLocationOids, then clicking both  
causes one to be overwritten.

To illustrate, when I submit your form, my server receives:  
Submitting with neither box checked  
Parameters: {“commit”=\>“Create”,  
“authenticity\_token”=\>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with the first box checked  
Parameters: {“commit”=\>“Create”,  
“selectedLocationOids”=\>“0000025354000000630d”,  
“authenticity\_token”=\>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with the second box checked  
Parameters: {“commit”=\>“Create”,  
“selectedLocationOids”=\>“000002527100000062bc”,  
“authenticity\_token”=\>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

Submitting with both boxes checked  
Parameters: {“commit”=\>“Create”,  
“selectedLocationOids”=\>“000002527100000062bc”,  
“authenticity\_token”=\>“1vYLmUq7Yc52/Z8Gum2qxQz9i2YyXYL0+/4AEu434Wg=”}

You can see that that even with both boxes checked, only receive one  
value,  
because they both have the same name. It might help you to read up on  
how  
hash tables work ([Hash table - Wikipedia](http://en.wikipedia.org/wiki/Hash_table))

- I’m on a Mac, so I can’t check your example, but I’m not sure what  
“ie”  
is. It looks like a variable ,but could be a method. If it is a method,  
I  
don’t see anything like it for Firefox, and their examples do not seem  
to  
behave the way you have used it ([Redirecting…](http://watir.com/examples/)) If it is a  
variable, then where was it initialized? It looks like you need to say  
ie =  
Browser.start(“[http://your-url.com](http://your-url.com)”)
