HTML & Javascript - Simple English-French Dictionary -
please bear utter lack of programming knowledge. goal publish simple , basic english-french dictionary run entirely locally. have capable of processing user input find corresponding meaning, usage , etymology, among few hundreds of entries.
here partly successful attempt only returns meaning:
<!doctype html> <html> <head> <meta charset="utf-8"> <link rel="stylesheet" type="text/css" href="style.css"> <title>english-french dictionary</title> </head> <body> <div id="result"></div> <script> if(typeof(storage)!=="undefined") { localstorage.setitem('apple','pomme'); } else { document.getelementbyid("result").innerhtml="sorry, browser not support web storage..."; } function myfunction() { var entryval = document.getelementbyid("entryinput"); var entryid = entryval.value; var entryresult = localstorage.getitem(entryid); document.getelementbyid("result").innerhtml="result: " + entryresult; } </script> <noscript>sorry, browser not support javascript!</noscript> <input id="entryinput" type="text"> <input type="button" value="search" onclick="myfunction()"> </body> </html> thus, question how enable multiple results? , considering terrible programming level, there better yet simple way?
if able provide english word, translation french, meaning, use, , etymology, should able store in javascript. lookup when user types in.
for example, you'd have structure:
var words = { "apple": { translation: "pomme", meaning: "fruit, red, sweet", use: "for eating", etymology: "from middle english appel" }, "bowling": { translation: "blah blah", meaning: "sport", use: "for recreation", etymology: "some old sport" } }; and myfunction perform lookup:
function myfunction() { var entryval = document.getelementbyid("entryinput"); var entryid = entryval.value.tolowercase(); if (entryid in words) { document.getelementbyid("result").innerhtml = "translation: " + words[entryid].translation; } else { document.getelementbyid("result").innerhtml = "not found"; } } this assuming have ability generate structure of information (word, translation, meaning, use, etymology).
here's demo of mean: http://jsfiddle.net/qsqqt/1/
i'm not sure using localstorage in code, doesn't seem necessary.
Comments
Post a Comment