Javascript to write cookie for state selector used on another page
This is the information that I received, but being a novice do not know what code to add to the attached javascript file or the page where the state is selected to make it work. Can anyone help me? The idea is that the person selects a state on one page that takes them to another URL. On that page, the user clicks another link that takes them to a page with a pre-selected state in the result based on the cookie initially selected.
Refer to: http://jason.pureconcepts.net/articles/javascript_cookie_object
- In the function setDDValue, a cookie can be set in the closure between line 117 and 124
- This cookie would have the same value as the variable 'value', passed in the function (i.e.: 'value' would be something like "Alaska")
- Since the Prototype library cannot "click" things programmatically, an event listener for a custom event needs to be created in order for it to work. Copy line 93, and paste it immediately after, and change it with a new custom even name, eg.:
On the page that needs to be smart enough to auto select the city:
- Read the cookie stored
- If cookie exists, fire the stateSelected event for the corresponding state link, ie: $('rrtaa67').fire('stateSelected'); where rrtaa67 is the ID name of the link in custom dropdown.
- This must be after the page has done loading, so bind it to the document load event. dropdown.js
JavaScriptHTML
Last Comment
BearWebContent
8/22/2022 - Mon
SRigney
You can probably use the Animate method from jQuery and the Comlete method. Once the animation is complete you could inject the link into the div at that point so the slide happens completely before the text appears.
I don't think you have to go through the code to click the state dropdown. You should be able to set the selected index to the value that matches the state stored in the cookie without needing to click on it.
At line 119 I think you need to add
Cookie.init({name: 'mydata'}, {state: Input.value, x: 0});
Then on the page that you want to set the value add the following javascript
document.observe("dom:loaded", function() {
$("selectboxTopreSet").value( Cookie.getData('state') );
$('selectboxTopreSet').fire('stateSelected');
});
BearWebContent
ASKER
Scenario:
I set the cookie using the form code below. Selecting a state from the drop-down takes me to xyz.html (or wherever else). On xyz.html is a link that opens a shadow box with another state selector that should be automatically open to the right state information. (See state-selector-xyz.html)
http://api.jquery.com/animate