Page 1 of 1

BrowserGetElement and checkboxes

PostPosted: Thu Jan 17, 2013 3:11 pm
by dpayer
I am working on a function to create dynamic objects by using the webbrowser object.

I want to get the values of input items, similar to submitting a web form. When I create the most common objects like text input, dropdowns, listboxes, etc. I can get the value entered using BrowserGetElement.
Example:
Code: Select all
<input type="radio" name="Data4" value="Mon">Mon<br>
<input type="radio" name="Data4" value="Tues">Tues<br>
<input type="radio" name="Data4" value="Wed">Wed<br>
<input type="radio" name="Data4" value="Thur">Thur<br>
<input type="radio" name="Data4" value="Fri">Fri<br>


in the form I can select one item (example: Thur) and when the code reads:
Code: Select all
BrowserGetElement "[%1]" "Data4" "[test]"

It will set the var's value as Thur

Checkboxes are different, they each require their own name as you can have multiple selections:
Code: Select all
<input type="checkbox" name="check4box1" id="check4box1" value="Mon">Mon<br>
<input type="checkbox" name="check4box2" id="check4box2" value="Tues">Tues<br>
<input type="checkbox" name="check4box3" id="check4box3" value="Wed">Wed<br>
<input type="checkbox" name="check4box4" id="check4box4" value="Thur">Thur<br>
<input type="checkbox" name="check4box5" id="check4box5" value="Fri">Fri<br>


in the form I can select one item (example: Thur) and when the code reads:
Code: Select all
BrowserGetElement "[%1]" "check4box4" "[test]"

It will set the var's value as Checked
In other words, it does not return the value, it returns the state.

I can work around this but it is an inconsistency with the way the action command works with other types of input and it is inconsistent with the way a web form submits data to a server. See this example: http://www.w3schools.com/TAGS/tryit.asp ... m_checkbox

It seems to work well with other input types.

David P.

Re: BrowserGetElement and checkboxes

PostPosted: Thu Jan 17, 2013 7:17 pm
by Gaev
DavidP:

Not sure if you were posting this as 'something you observed' or 'seeking help' in getting the 'value' returned to your Pub.

If you try this code ...
Code: Select all
<!DOCTYPE html>
<html>
<body>
<form action="demo_form.asp" method="get">
  <input type="checkbox" id='vehBike' name="vehicle" value="Bike"> I have a bike<br>
  <input type="checkbox" id='vehCar' name="vehicle" value="Car" checked="checked"> I have a car<br>
  <input type="submit" value="Submit">
</form>
<script>
bikeValue = document.getElementById('vehBike').value;
document.write(bikeValue)
carValue = document.getElementById('vehCar').value;
document.write(carValue)
</script>
</body>
</html>
... and click on Submit code, you will see how you can extract the 'xxxx' from the 'value=xxxx' parameters in such elements.

So, in your case, when BrowserGetElement returns Checked ... you could follow it up with a BrowserExecScript that returns the result of a command like 'document.getElementById('elementId').value;' ... where 'elementId' is the previously assigned id for the particular checkbox element.

Hope that helps.

Re: BrowserGetElement and checkboxes

PostPosted: Thu Jan 17, 2013 7:50 pm
by dpayer
Gaev,

Thanks for the tip. I wasn't sure if that was the intended behavior of that command with checkboxes. I would have thought it would grab the value if it was defined. I found a way to get the data but I like your suggestion.

David

Re: BrowserGetElement and checkboxes

PostPosted: Fri Jan 18, 2013 12:00 pm
by Neosoft Support
...It will set the var's value as Checked
In other words, it does not return the value, it returns the state.

I can work around this but it is an inconsistency with the way the action command works with other types of input and it is inconsistent with the way a web form submits data to a server. See this example: http://www.w3schools.com/TAGS/tryit.asp ... m_checkbox


I will look into this.