Richard Bennett
asked on
Wordpress Jquery Function Not Working: Selection List Function Not Working Properly in Wordpress Website.
Background: I have a function which I wrote, which allows me to select an option from one list and set the default selection of another list. (See the code file attached). This file works really well, perfectly as a matter of fact.
Problem:
When I try and run this jQuery function on a Wordpress Site using the exact same "Element ID's" and code from the attached HTML file, it completely fails.
What I have tried so far:
1. I have tried to place the code inside the body of the page, the header of the page as well as the footer. Nothing worked.
2. I have tried to change the element ID's, nothing.
3. When I am logged into Wordpress and I select an option, and refresh the page, the selection works, but only after REFRESHING the page.
4. I have tried to debug the Wordpress page in question, but to no avail, the code just does not work there. There is not anything to debug - it just won't work. What am I missing?
5. I know I am using the right element id's because when I use the code from the attached jqsnippet.txt file, it tells me which element value I have selected, when I select it.
6. Also, I need to have completely autonomous code, because I am manipulating values from the "Post Type Builder" plugin. Should not matter however, I should be able to type TWO ELEMENT ID's into the function and be off to the races. I just need to get the existing function, or something similar to work in my Wordpress site.
The WordPress page in question is here: http://www.wjdoe.com/firstowner/testing/
jQuery/JS Element Finder:
jqsnippet.txt
HTML That Works
Selection_Tester3.html
If anyone could please help me with this, it would be much appreciated. I am essentially pulling my hair out, at this point. The solution to this is probably trivial, but I could use all of the help I can get. I am not looking for the complete answer here, just a place to start. A complete answer would be nice, just not expected ;)
Problem:
When I try and run this jQuery function on a Wordpress Site using the exact same "Element ID's" and code from the attached HTML file, it completely fails.
What I have tried so far:
1. I have tried to place the code inside the body of the page, the header of the page as well as the footer. Nothing worked.
2. I have tried to change the element ID's, nothing.
3. When I am logged into Wordpress and I select an option, and refresh the page, the selection works, but only after REFRESHING the page.
4. I have tried to debug the Wordpress page in question, but to no avail, the code just does not work there. There is not anything to debug - it just won't work. What am I missing?
5. I know I am using the right element id's because when I use the code from the attached jqsnippet.txt file, it tells me which element value I have selected, when I select it.
6. Also, I need to have completely autonomous code, because I am manipulating values from the "Post Type Builder" plugin. Should not matter however, I should be able to type TWO ELEMENT ID's into the function and be off to the races. I just need to get the existing function, or something similar to work in my Wordpress site.
The WordPress page in question is here: http://www.wjdoe.com/firstowner/testing/
jQuery/JS Element Finder:
jqsnippet.txt
HTML That Works
Selection_Tester3.html
If anyone could please help me with this, it would be much appreciated. I am essentially pulling my hair out, at this point. The solution to this is probably trivial, but I could use all of the help I can get. I am not looking for the complete answer here, just a place to start. A complete answer would be nice, just not expected ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
leakim971, you are the man sir! If I knew where you were I would by you beer, nay I would buy you a KEG of Beer + Plus 2 Six Packs! I cannot thank you enough! This works perfectly. And to the powers that be at Experts Exchange - you just made me a lifetime member.
1. You go to all the trouble of including jQuery and defining a .ready() function and then use plain getElementById to access your elements?
2. In your test code you have the line
Suggesting that select 2 should change and only show items relating to select 1 - instead it just selects the first item that pertains to the first.
3. Not sure what the snippet is meant to achieve - doesn't appear to do anything - but I would have expected it to be linked to an onchange on the first.
4. You are setting an id on each of your options - not sure why?
What you probably want is dynamically assigned dropdowns where 2 populates based on the value of 1
Something like this
HTML
Options here - either put a -- SELECT MAKE -- and -- SELECT MODEL -- as default items - or make the second default to only the Honda items as that will be the default on load
Open in new window
jQueryOpen in new window
Note we have a data structure that breaks the options down by first option. We then use the value of the first select to populate the second.You can see your example working here
There is another sample you can look at here
Now looking at your WordPress site you have this
Open in new window
What do you notice about this select compared to yours?1. No id's
2. value attributes
In your HTML sample - the value will default to the label because you did not define a value
In the Word Press sample this is not the case.
So if you are going to use the sample above you will have to change the models array to use the values in the selects rather than the sample values.