...

View Full Version : dropdown value



adayzdone
12-11-2011, 09:14 PM
I am just learning but this is driving me nuts. Any help would be appreciated.

I am trying to change the value of a quantity dropdown on this page:
http://www.walmart.com/ip/Energizer-522BP-2-Energizer-Max-9-Volt-2-Pack/872068#rr

This will change it in the browser but the 3 value is not retained when I add the item to cart. Do I have to do something with onchange? What?


document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].value= 3

Philip M
12-11-2011, 09:45 PM
How is it that you are trying to change a variable on Walmarts' order page? You cannot do that.

For security reasons JavaScript cannot access anything beyond the domain of the current page. This is known as the "same origin policy" and prevents a document or script loaded from one origin from getting or setting properties of a document from a different origin.


It is your responsibility to die() if necessary….. - PHP Manual

adayzdone
12-11-2011, 09:54 PM
How is it that you are trying to change a variable on Walmarts' order page? You cannot do that.

From within an applescript:

tell application "Safari"
activate
set available to do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].length" in document 1
do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].value= " & (available as text) & "" in document 1
end tell

Again, I am able to update the dropdown so it displays a different value. However, when I click the submit button only one item is added to cart.

Old Pedant
12-11-2011, 11:06 PM
It's not really proper to change the .value of a <select>.

You really should instead change the selectedIndex.

So try that:


tell application "Safari"
activate
set available to do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].length" in document 1
do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].selectedIndes=3;" in document 1
end tell

If that works, then you may have to write code that looks up the selectedIndex by way of the .value and then sets it.

adayzdone
12-12-2011, 05:37 AM
Thanks for the selected index direction. That got me to where I needed to be.


set available to (do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].length" in document 1) - 1
do JavaScript "document.getElementsByClassName('stripitems')[0].childNodes[3].childNodes[3].selectedIndex= " & (available as text) & "" in document 1



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum