Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: dropdown value

  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    dropdown value

    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-...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?

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

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    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

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    How is it that you are trying to change a variable on Walmarts' order page? You cannot do that.
    From within an applescript:
    Code:
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,216
    Thanks
    75
    Thanked 4,344 Times in 4,310 Posts
    It's not really proper to change the .value of a <select>.

    You really should instead change the selectedIndex.

    So try that:
    Code:
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for the selected index direction. That got me to where I needed to be.

    Code:
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •