Wednesday, 15 July 2015

javascript - document.getElementById.innerHTML does not write anything ..? -



javascript - document.getElementById.innerHTML does not write anything ..? -

my problem:

document.getelementbyid("values").innerhtml not write anything. if seek document.getelementbyid("values").innerhtml = "stuff"; (just string) - nil happens.

what doing wrong here?

html: <form onsubmit="save_entry();return false;"> <label for="i_km">kilometer: <input type="text" name="km" id="i_km"></label><br> <label for="i_fuel">sprit: <input type="text" name="fuel" id="i_fuel"></label><br> <input type="submit" value="save" /> </form> <div id="values"></div> javascript: function save_entry() { var anzahl = localstorage.length/2; var namekeykm = "k" + anzahl; localstorage.setitem(namekeykm,document.forms[0]["km"].value); var namekeyf = "f" + anzahl; localstorage.setitem(namekeyf,document.forms[0]["fuel"].value); document.write("entry saved!") } function show_entry() { document.getelementbyid("values").innerhtml = "<table><th>kilometers</th><th>tanked</th>"; (var = 0; < localstorage.length/2; i++) { alert("d"); var temp_km = "k"+i; var temp_f = "f"+i; document.getelementbyid("values").innerhtml = "<tr>"; document.getelementbyid("values").innerhtml = "<td>"+localstorage.getitem(temp_km)+"</td>"; document.getelementbyid("values").innerhtml = "<td>"+localstorage.getitem(temp_f)+"</td>"; document.getelementbyid("values").innerhtml = "</tr>"; } document.getelementbyid("values").innerhtml = "</table>"; } show_entry();

this work!

function show_entry(){ var content = ''; content = content + '<table><th>kilometer</th><th>getankt</th>'; for(var = 0; < localstorage.length/2; i++) { var temp_km = "k"+i; var temp_f = "f"+i; content = content + "<tr>"; content = content + "<td>"+localstorage.getitem(temp_km)+"</td>"; content = content + "<td>"+localstorage.getitem(temp_f)+"</td>"; content = content + "</tr>"; } content = content + "</table>"; document.getelementbyid("values").innerhtml = content; }

javascript html

No comments:

Post a Comment