As you can see i have done a page with two jump menus, as I cant style selects properly, Iāve attempted to spit them out as liās so i can style them so I have got up to this point, the problem i have is that the top menu it should only say 1, 2, 3 and the bottom one 4, 5, 6 at the moment it spits it out as 1,2,3,4,5,6 on both menus.
I had a look at your code.
The problem is that you are creating your unordered list (with six list items), then you are inserting it twice (once before each input element).
Here are a couple of observations to your code:
[LIST]
[]var list = $('<ul>'); - here you are telling jQuery to get all of the <ul> tags it can find on the page. However, there are none.
[]$('.menu option').each(function () { - here you are finding any elements with the class āmenuā, getting a reference to each <option> tag contained within these element and attaching a function to it. This in itself is fine.
[]$('select').hide(); - however, for each <option> tag jQuery finds, it will now try and find all the <select> tags within the document and hide them. This should not be within the loop, as it only needs to be done once.
[]list.insertBefore($('input')); - This is whatās causing the list to display twice. jQuery is getting a reference to both input tags in the document (the two submit buttons) and inserting the list it has just created before them.
[/LIST]So, I rewrote yourcode a little. I gave each <select> element a unique id. Now, this should more or less do what you want:
My only remaining question is: is there any reason you didnāt use list items in the first place?
Iām not sure how you are intending to submit your form with this approach.
Nonetheless, I hope this helps you.
If you have any questions, just let me know.
Hello Pullo many thanks for your reply, Iāve learned some new things there such as replaceWith didnt know you could that, many thanks for showing me this yes thats what i wanted to do, idās crossed my mind however i thought as it was a separate item it would do everything that was in that select but this isnt the case, in terms of the purpose there are some sites I am building in the future use jump menus to navigate parts of the site, so its going to work as a jump menu but using liās to get better styling, the user selects an item from the drop down and then presses āGoā to navigate to that page thanks for your help I am i think 50% there, I am gonna try this weekend to implement the other half
Hi Pullo finally got round to adding some more script to make the jumpmenu work correctly, its now looking like this http://www.harshadpatel.co.uk/selectbox/ and its now working correctly, many thanks for your help Pullo in helping me with this :), the next thing i want to do is make it more modular so it can be dropped easily into any pagee and I am going to try and turn this into a plugin as i havent done one and is something i need to learn Just one question if i want to use classes instead of idās to seperate the menu items is this possible?
Iāve got a lot to learn but i think i am making some progress
will of course return undefined, as the <select> element, doesnāt have a value attribute or text() method.
So what you should do within the function passed to each, is to get all of the children of the select element (the <option> elements), so that you can manipulate them in some way.
You can do this with the map() function, like this:
Aah yes it makes sense now because when i did a console.log with your code it pinpointed the options, then when i did it only picked out the select value, its something i need to look into traversing the dom using Javascript, many thanks for showing me this