Campo calcolato con DOM

  • Creatore Discussione Creatore Discussione Ghena
  • Data di inizio Data di inizio

Ghena

Utente Attivo
3 Mar 2005
58
0
0
tramite una funzione sto aggiungendo una riga ad uan tabella.
Ad una cella di questa tabella, appendo un campo input che mi permetta di fare semplici operazioni matematiche.

Ho provato cosi:


var td3 = document.createElement("TD")
var sel1 = document.createElement("INPUT")
sel1.setAttribute('name','4_letto_rid')
sel1.setAttribute('value',4+'rid'+liv+num)
sel1.setAttribute('OnChange','document.getElementById("'+4+'rid'+liv+num+'").value = eval(this.value)')
sel1.setAttribute('id',(4+'rid'+liv+num))
sel1.setAttribute('size','5')
td3.appendChild(sel1)


con FF funziona con IE no!!
 
"innanzitutto getElementB yId si scrive attacato"

beh anche "attaccato" si scrive con 2 "c" ;)

poi cosa vuol dire non quaglia... ?

Non funziona... non da nessun errore, quindi penso che l'errore sia sull'evento onchange, o meglio sul fatto che non venga preso in cosiderazione l'evento.

Ieri ho riprovato... a richiamare una semplice funzione con un parametro fisso:

var td3bis = document.createElement("TD")
var sel0 = document.createElement("SELECT")
sel0.setAttribute('name','tipo_pax_new')
sel0.setAttribute('OnChange','appendi("ADT");')
td3bis.appendChild(sel0)

la funzione è:

Function appendi(param)

{
if((param) == 'ADT'){
document.getElementById('age1').value = '--';document.getElementById('age2').value = '--'};

if((param) == 'CHD'){
document.getElementById('age1').style.background = '#ffff00';
document.getElementById('age1').readOnly = false;
document.getElementById('age2').style.background = '#ffff00';document.getElementById('age2').readOnly = false;
}

}
</script>

Risultato con FF funziona con IE no, ne da errore.
 
grazie luke....


faccio riferimento al secondo link...

sezione document
' questa la prendo dalla mia funzione
sel0.setAttribute('OnChange','appendi("ADT");')

Syntax: document.event_name="someJavaScriptCode"
quindi dovrei fare:


sel0.document.onchange="appendi('ADT');"

confermi?
 
allur....

ho provato un pò in tutte le salse... ma non gli garba.

<script>
function appendi(param)

{
if((param) == 'ADT'){
document.getElementById('age1').value = '--';};

if((param) == 'CHD'){
document.getElementById('age1').style.background = '#ffff00';
document.getElementById('age1').readOnly = false;
}

}
</script>

<script>
function aggiungi(){
var tbody = document.getElementById('table').getElementsByTagName("TBODY")[0];
var row = document.createElement("TR")

var td1= document.createElement("TD")
var sel0 = document.createElement("SELECT")
sel0.setAttribute('name','tipo_pax_new')
sel0.document.onchange="appendi('CHD');"
td1.appendChild(sel0)

var optsel =document.createElement("OPTION");
theText=document.createTextNode("--Seleziona--");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var optsel =document.createElement("OPTION");
theText=document.createTextNode("ADT");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var optsel =document.createElement("OPTION");
theText=document.createTextNode("CHD");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var td2= document.createElement("TD")
var sel0 = document.createElement("INPUT")
sel0.setAttribute('name','age1_new')
sel0.setAttribute('size','5')
sel0.setAttribute('id','age1')
sel0.setAttribute('readOnly','readOnly')
td2.appendChild(sel0)


row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
 
quello è il codice :quote:

vuoi anche l'html???

te lo ripasso....

-----------------------

<script>
function appendi(param)

{
if((param) == 'ADT'){
document.getElementById('age1').value = '--';};

if((param) == 'CHD'){
document.getElementById('age1').style.background = '#ffff00';
document.getElementById('age1').readOnly = false;
}

}
</script>

<script>
function aggiungi(){
var tbody = document.getElementById('table').getElementsByTagN ame("TBODY")[0];
var row = document.createElement("TR")

var td1= document.createElement("TD")
var sel0 = document.createElement("SELECT")
sel0.setAttribute('name','tipo_pax_new')
sel0.document.onchange="appendi('CHD');"
td1.appendChild(sel0)

var optsel =document.createElement("OPTION");
theText=document.createTextNode("--Seleziona--");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var optsel =document.createElement("OPTION");
theText=document.createTextNode("ADT");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var optsel =document.createElement("OPTION");
theText=document.createTextNode("CHD");
optsel.appendChild(theText);
sel0.appendChild(optsel);

var td2= document.createElement("TD")
var sel0 = document.createElement("INPUT")
sel0.setAttribute('name','age1_new')
sel0.setAttribute('size','5')
sel0.setAttribute('id','age1')
sel0.setAttribute('readOnly','readOnly')
td2.appendChild(sel0)


row.appendChild(td1);
row.appendChild(td2);
tbody.appendChild(row);
}
</script>

<table border="0" width="100%" cellpadding="0" id="table" height="20" cellspacing="0">
<td>Tipo pax</td>
<td>Age1</td>

<td><a href="javascript:;" onclick="javascript:aggiungi();">nuovo</a></td>
</tr>
<tbody>
</tbody>

</table>
--------------------------------------------

ora è tutto .. credo...
 
incredibile anche tu non ci sei riuscito...?!

solo il grande nello otupacca può risolvere questa cosa?


:)
 

Discussioni simili