Source language: Translate to:

BrowserGetElement and checkboxes

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

BrowserGetElement and checkboxes

Postby dpayer » Thu Jan 17, 2013 3:11 pm

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.
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: BrowserGetElement and checkboxes

Postby Gaev » Thu Jan 17, 2013 7:17 pm

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.
User avatar
Gaev
 
Posts: 3718
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Re: BrowserGetElement and checkboxes

Postby dpayer » Thu Jan 17, 2013 7:50 pm

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
David Payer
Des Moines, Iowa
USA
User avatar
dpayer
 
Posts: 1380
Joined: Mon Apr 11, 2005 5:55 am
Location: Iowa - USA

Re: BrowserGetElement and checkboxes

Postby Neosoft Support » Fri Jan 18, 2013 12:00 pm

...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.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5593
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest