Ciao a tutti ragazzi
Sono un principiante, ed ho provato a creare un tabella con il suo linguaggio javascript, ecco a voi il codice:
Fatto sta che ci sn dei problemi..l'elemento td che contiene "Costo benzina:" (l'ultimo) vorrei che stesse allineato al centro della tabella ma non capisco perchè non funziona..inoltre la funziona finale servirebbe per rendere invisibile l'elemento td contenente costo benzina ma non funziona..qualcuno può darmi una mano per cortesia?<script type="text/javascript"> contenuto=document.getElementById("contenuto"); form1=document.createElement("form"); form1.setAttribute("name","benzina"); form1.setAttribute("id","benzina"); contenuto.appendChild(form1); tabella=document.createElement("table"); tabella.setAttribute("align","center"); td1=document.createElement("td"); td1.appendChild(document.createTextNode("Inserire numero di persone presenti nel veicolo:")); td2=document.createElement("td"); inp1=document.createElement("input"); inp1.setAttribute("type","text"); inp1.setAttribute("name","uno"); td2.appendChild(inp1); tr1=document.createElement("tr"); tr2=document.createElement("tr"); td3=document.createElement("td"); td4=document.createElement("td"); inp2=document.createElement("input"); inp2.setAttribute("type","text"); inp2.setAttribute("name","due"); td4.appendChild(inp2); td5=document.createElement("td"); td6=document.createElement("td"); inp3=document.createElement("input"); inp3.setAttribute("type","text"); inp3.setAttribute("name","tre"); td6.appendChild(inp3); td7=document.createElement("td"); td8=document.createElement("td"); inp4=document.createElement("input"); inp4.setAttribute("type","text"); inp4.setAttribute("name","quattro"); td8.appendChild(inp4); tdfinale=document.createElement("td"); tdfinale.setAttribute("colspan","2"); tdfinale.setAttribute("align","center"); button=document.createElement("input"); button.setAttribute("type","button"); button.setAttribute("value","Calcola"); button.setAttribute("onclick","calcola()"); tdfinale.appendChild(button); tabella.appendChild(td1); tabella.appendChild(td2); tabella.appendChild(document.createElement("tr")); tabella.appendChild(td3.appendChild(document.creat eTextNode("Inserire prezzo al litro del carburante:"))); tabella.appendChild(td4); tabella.appendChild(document.createElement("tr")); tabella.appendChild(td5.appendChild(document.creat eTextNode("Inserire distanza il km dal luogo di partenza a\n quello di arrivo"))); tabella.appendChild(td6); tabella.appendChild(document.createElement("tr")); tabella.appendChild(td7.appendChild(document.creat eTextNode("Inserire quanti km riesce a percorrere l'auto con un litro di carburante:"))); tabella.appendChild(td8); tabella.appendChild(document.createElement("tr")); tabella.appendChild(tdfinale); tabella.appendChild(document.createElement("tr")); tdcb=document.createElement("td"); tdcb.setAttribute("colspan","2"); tdcb.setAttribute("align","center"); tabella.appendChild(tdcb.appendChild(document.crea teTextNode("Costo benzina:"))); form1.appendChild(tabella); function calcola(){ tdcb.display="none"; }
Grazie mille e scusatemi della perdita di tempo.
Buona domenica a tutti voi.
Marco