Grubler Posted April 24, 2012 Share Posted April 24, 2012 Hello. I hope that someone can point me in the right direction. I'm designing a wesite and would like to have som dynamic content.I know how to use the js inside of the html with innerHTML. But I would like the JavaScript to get the description text from a text file or a mySql. This is much easier to maintain than have to edit the html every time I want to change the description text. The site contains a list of items and a field for description.Something like this: <li id="lst_head" class="header1">Items<ul class="txt_lst"><li id="id_lamp">Lamp</li><li id="id_heater">Heater</li></ul></li> Then i have a div where the description is supposed to "pop" up. <div class="lst_def_txt" id="></div> So, how to make a script that get some text form a file or database and place it in the div when I click an item in the list? Regards,Jon Link to comment Share on other sites More sharing options...
thescientist Posted April 24, 2012 Share Posted April 24, 2012 You need knowledge of a server side scripting language like PHP and familiarity with SQL, all can be found in the tutorials section of W3Schools. Link to comment Share on other sites More sharing options...
Grubler Posted April 24, 2012 Author Share Posted April 24, 2012 Server side? Well, since it is the user clicking the item to get more info, it is client side.Earlier I have used the innerHTML to get the info text.Like this<html><body><li id="lst_head" class="header1">Items<ul class="txt_lst"><li id="id_lamp" onclick="lst_def_txt.innerHTML='Some text about lamp.'">Lamp</li><li id="id_heater" onclick="lst_def_txt.innerHTML='Some text about heater.'">Heater</li></ul></li><div id="lst_def_txt"></div></body></html> But it is a pain in the *** maintaining the description text. Therefore I would like to get the description text from a text file or from a database. /Jon Link to comment Share on other sites More sharing options...
thescientist Posted April 24, 2012 Share Posted April 24, 2012 right, the click event is client side. but if you want to interact with database on the server or write to a file on the server, well, you can see what kind of language that will need. If you just want to maintain a text file instead of a DB, then you can just use JS to read from it, and manually update it yourself, although a DB is usually a cleaner, easily maintainable, and more organized way to go. Depends on your needs and the extent of your application. Link to comment Share on other sites More sharing options...
Grubler Posted April 24, 2012 Author Share Posted April 24, 2012 Yes of course if I would write to a db or txt that clearly is something else.But here I just want to get the info FROM a txt or db.Lets say I have a file description.txt on the server. This file contains something like[Lamp]This is description for the lamp.[Heater]This is the description for the heater Then how can I get this text and use it to fill the div in my html for the onclick event? Link to comment Share on other sites More sharing options...
thescientist Posted April 24, 2012 Share Posted April 24, 2012 If you need to read a text file in the manner you described, then use AJAX.http://www.w3schools.com/ajax/default.asp Anything to do with a DB will require a server side language. Any writing to a file other than manually editing it yourself in a text editor will also require a server side language. Link to comment Share on other sites More sharing options...
Grubler Posted April 24, 2012 Author Share Posted April 24, 2012 Thanks, that looks like something I can use Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.