0

My website has individual pages for members, but I have a select menu used to scroll from one member to the other. I have the select menu coded in the html on every page, but I need a better solution since my membership is growing.

I need to be able to create that same select menu in a separate file with the ability, when selected to jump to another member page, have that embedded in the body where I need it so that all I have to do is alter/ update the external file and it'll be done for all the member pages.

I've looked into javascripting it, mysqling it, but can't find (looking on youtube) a code to exactly help me in what I need.

My typical code for the select

//(select..... //(option value="http:www.website-Profile-blahblah.html.... so on and so forth.

I need to pull this from an external file to use across the board and place it in the body where I need it.

thanks for any help you can offer.

3 Answers3

0

In general this sounds like something you should be using a back end rendering engine for. As far as the select goes, this would be a great place to use a dropdown menu such as the one provided by bootstrap since clicking a select won't actually move you to another page. If you dont want to use/can't use a back end rendering engine to render the options, I would suggest looking at angular.js which has a great ng-repeat and ng-option feature that would allow you to dynamically build the select/dropdown with as many users as you want.

angular ng-repeat page: https://docs.angularjs.org/api/ng/directive/ngRepeat

bootstrap dropdown: http://www.w3schools.com/bootstrap/bootstrap_dropdowns.asp (note the a tags could go directly to the user's page)

Silvertail
  • 169
  • 1
  • 13
  • the bootstrap_dropdown method looks to be only used in the body of the html is I'm not mistaken. Looking at the link sent it only appears to be using it in the page I want the menu to show up in and not pulling that menu with the links from an external file. The external file is the only thing I really want to alter or update for all pages. sorry. a little new at code writing and not versed in most of the sql formulas. – Marimbakat Apr 20 '16 at 14:12
0

From experience in cases like this, it is much easier to have an SQL table to store the links you would like to use. The next thing to do is to have your back-end send you the list of links. With this, you can dynamically create the option tag and append it to your select tag. functions like newOptionTag.setAttribute('value', 'url'),document.createElement('option') and selectElement.appendChild(newOptionTag) should help you on your way

  • I can see using the mysql tables, but I'm a little confused as to how I can use the 'url' in the table. When I first was looking at making the table I placed 3 columns available. 'id', 'name', 'value'. The id I of course had an an INT and VARCHAR for the other two. I would assume the value on the 'value', which I would more or less refer to as the "url" would be the link to where i want it to go, but the code has gotten me confused on how to write it. I've looked through so much stuff it's all mixed up in my head over the past two days. Thanks again for any help. – Marimbakat Apr 20 '16 at 14:51
  • Are you using any back-end and if you are, what language is in?? – Delanyo Aborchie Apr 20 '16 at 15:42
  • I've only mostly been versed a little in html. by back-end I would think all I'm using is script files .js and such. Again, amateur at this it seems. I know what I want to do, but execute it is scrambling my brain. paying someone to do it might be my best option. I've looked into the json file, and that seems an easier way that others, but creating that select menu as I have now on my html on each member page is where I think the hitch is – Marimbakat Apr 20 '16 at 16:21
  • I should note that every video I look at for code usage uses .document of some sort. I'm not looking into uploading a document or just the info into a certain part of the page, but rather a select menu to choose what member to go to. take a look at www.seetheair.com/Profile-ant1897.html this is a member, – Marimbakat Apr 20 '16 at 16:35
  • From experience I have known it to be safer to mysql to store the data and use a back end language like php or ruby to pull the data and display it. Conversely you could store the urls in a file and read it using javascript. there is an example in this question http://stackoverflow.com/questions/14446447/javascript-read-local-text-file – Delanyo Aborchie Apr 21 '16 at 00:03
0

If you really want to use a seperate file, you could store the membernames and links in a json file. On document load get the file, parse it, then use the object to build the options.

The w3schools website (though frowned upon by some) has a json tutorial and an example that is already halfway there.

EDIT: I see it actually uses mysql to build the json file...

yezzz
  • 2,990
  • 1
  • 10
  • 19