Autore Topic: errato funzionamento evento on Change su Select  (Letto 1974 volte)

0 Utenti e 1 Visitatore stanno visualizzando questo topic.

Offline stiffa

  • Post: 12
errato funzionamento evento on Change su Select
« il: 22 Novembre 2005 10:18:27 »
Allora ragazzi..una medaglia al valore a chi riesce a farmi andare lo script. Praticamente la parte in causa e' la funzione javascript "change()". E' tutta giusta, i nomi ecc, l'ho provata anche su altre pagine prendendo da questo codice solo il necessario, ossia la form e la function change.
Si tratta di una semplice funzione che in base ai 2 valori della select abilita o disabilita gli input.
Dopo una mattinata di smanettamento sono arrivato a dire che in tutto sto codice c'e' qualcosa che ostacola questa cosa... piu esattamente secondo me sono i div che ho usato per la tab dialog... ho notato che se il codice della form lo metto fuori dalla TAB DIALOG (il menu a tendina) funziona perfettamente...please help me...spero di eesermi spiegato bene.

ecco il codice
Codice: [Seleziona]



<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>SimplytheBest DHTML tabbed notes script</title>
<link rel = "stylesheet" type = "text/css" href = "../css/hyperlife.css">
<meta name="keywords" content="DHTML scripts, tab, notes, messages">
<meta name="keywords" content="DHTML scripts, tabbed notes, tab, notes, dhtml script, javascript">
<meta name="description" content="Simply the Best DHTML scripts and javascripts: tabbed notes.">
<meta name="target" content="DHTML scripts, tabbed notes">
<meta name="copyright" content="copyright 1997-2005 SimplytheBest.net">
<meta name="revisit-after" content="14 days">
<meta name="robots" content="all">
<link rel="stylesheet" href="../scripts.css" type="text/css">
<style>
<!--
.conts { visibility: hidden }
.tab { font-family: Verdana; font-size: 8pt; font-weight: normal; text-align: center;
border-left: thin solid #e0e0e0; border-right: thin solid gray;
border-top: thin solid #e0e0e0;
cursor: hand;
}
.selTab { font-family: Verdana; font-size: 8pt; font-weight: bold; text-align: center;
border-left: thin solid #000080;
border-right: thin solid #000080;
border-top: thin solid #000080;
cursor: hand;
}
-->
</style>
<script language = "javascript" type="text/javascript">

function change()
{

var select = document.theForm.dhcp.value;


if(select=="yes")
{

document.theForm.hostName.disabled = true;
document.theForm.ipAddress.disabled = true;
document.theForm.gateway.disabled = true;
document.theForm.dns1.disabled = true;
document.theForm.dns2.disabled = true;
document.theForm.macAdd.disabled = true;
document.theForm.subnet.disabled = true;
}
else
{

document.theForm.hostName.disabled = false;
document.theForm.ipAddress.disabled = false;
document.theForm.gateway.disabled = false;
document.theForm.dns1.disabled = false;
document.theForm.dns2.disabled = false;
document.theForm.subnet.disabled = false;
document.theForm.macAdd.disabled = false;
}
}


// Courtesy of SimplytheBest.net - http://simplythebest.net/scripts/
//a public function that the container uses to pass in values for the labels
function public_Labels(label1, label2, label3, label4, label5, label6, label7){

document.getElementById("t1").innerText = label1;
document.getElementById("t2").innerText = label2;
document.getElementById("t3").innerText = label3;
document.getElementById("t4").innerText = label4;
document.getElementById("t5").innerText = label5;
document.getElementById("t6").innerText = label6;
document.getElementById("t7").innerText = label7;
}
//a public function that the container uses to pass in values for the card containers
function public_Contents(contents1, contents2, contents3, contents4, contents5, contents6, contents7){
document.getElementById("t1Contents").innerHTML = contents1;
document.getElementById("t2Contents").innerHTML = contents2;
document.getElementById("t3Contents").innerHTML = contents3;
document.getElementById("t4Contents").innerHTML = contents4;
document.getElementById("t5Contents").innerHTML = contents5;
document.getElementById("t6Contents").innerHTML = contents6;
document.getElementById("t7Contents").innerHTML = contents7;
init();
}
//sets the default display to tab 1
function init(){
document.getElementById("tabContents").innerHTML = document.getElementById("t1Contents").innerHTML;
}
//this is the tab switching function
var currentTab;
var tabBase;
var firstFlag = true;
function changeTabs(tabID){
if(firstFlag == true){
currentTab = document.getElementById("t1");
tabBase = document.getElementById("t1base");
firstFlag = false;
}
if(document.getElementById(tabID).className == "tab"){
currentTab.className = "tab";
tabBase.style.backgroundColor = "white";
currentTab = document.getElementById(tabID);
tabBaseID = currentTab.id + "base";
tabContentID = currentTab.id + "Contents";
tabBase = document.getElementById(tabBaseID);
tabContent = document.getElementById(tabContentID);
currentTab.className = "selTab";

tabBase.style.backgroundColor = "";
document.getElementById("tabContents").innerHTML = tabContent.innerHTML;
}
}
</SCRIPT>
</head>
<body onload="init()" text="#000000" link="#0000A0" vlink="#0000A0" alink="#0000A0" topmargin="10" leftmargin="10" marginheight="10" marginwidth="10">
<!-- DHTML scripts, tabbed notes script -->


<!-- Script start -->

<table bgcolor="#FFA500" cellpadding="0" cellspacing="0" style="HEIGHT: 500px; WIDTH: 800px" class="body" ID="Table1">
<tbody>
<tr>
<td class="selTab" onclick="changeTabs('t1')" height="25" id="t1">TwineXp</td>
<td class="tab" onclick="changeTabs('t2')" id="t2">Network</td>
<td class="tab" onclick="changeTabs('t3')" id="t3">Emulatore</td>
<td class="tab" onclick="changeTabs('t4')" id="t4">Utenti</td>

</tr>
<tr>
<td id="t1base" style="BORDER-LEFT: gray thin solid; HEIGHT: 1px"></td>
<td id="t2base" style="BACKGROUND-COLOR: white; HEIGHT: 1px"></td>
<td id="t3base" style="BACKGROUND-COLOR: white; HEIGHT: 1px"></td>
<td id="t4base" style="BACKGROUND-COLOR: white; HEIGHT: 1px"></td>

</tr>
<tr>
<td colspan="7" height="*" id="tabContents" style="BORDER-BOTTOM: gray thin solid; BORDER-LEFT: gray thin solid; BORDER-RIGHT: gray thin solid"> </td>
</tr>
</tbody>
</table>
</div>
<div class="conts" id="t1Contents" style="width: 500; height: 10">
</div>
<div class="conts" id="t2Contents" style="width: 459; height: 120">
<form action = "" method = "post" name = "theForm">
<table cellspacing="5" cellpadding="5" border = "1" align = "center" width = "380" bgcolor="#ffffff">

<tr>
<td width = "150" align = "center"><img src="TMimagesAlt/net.bmp" border="0"></td>
<td>Ip config</td>
</tr>
<tr>
<td>Dhcp :</td>
<td>
<select name = "dhcp" onChange = "change();">
<option value = "no">no</option>
<option value = "yes">yes</option>

</select>
</td>
</tr>

<tr>
<td>Host Name:</td>
<td><input type = "text" name = "hostName"></td>
</tr>
<tr>
<td>IP Address:</td>
<td><input name="ipAddress" type="text"></td>
</tr>
<tr>
<td>Subnet Mask :</td>
<td><input name="subnet" type="text" ></td>
</tr>
<tr>
<td>Gateway :</td>
<td><input name="gateway" type="text" ></td>
</tr>
<tr>
<td>Mac Address :</td>
<td><input name="macAdd" type="text"></td>
</tr>

<tr>
<td>Dns primary :</td>
<td><input name="dns1" type="text" ></td>
</tr>
<tr>
<td>Dns secondary :</td>
<td><input name="dns2" type="text" ></td>
</tr>

<tr>
<td align = "center" colspan ="2">
<table cellspacing="5" cellpadding="5" align ="center">

<tr>
<td><input type="submit" value="OK"></td>
<td><input type="reset" value="Cancel"></td>
<td><input type="submit" value="Help"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</div>
<div class="conts" id="t3Contents" style="width: 460; height: 38">
<table valign = "top" align = "center" width = "700" >
<tr>
<td width = "150" colspan ="2">
<img src = "TMimagesAlt/spacer.gif" height = "20">

<table align = "center" valign = "top" cellspacing = "10" width = "300">
<tr>
<td><a href = "http://www.google.it" target = "pippo">Open</a></td>
<td><a href = "http://www.google.it" target = "pippo">Close</a></td>
<td><a href = "addConnHost.php" target = "pippo"><img src ="TMimagesAlt/addConn32.bmp" alt = "add connection" border = "0"></a></td>
<td><a href = "addSessionDisp.php" target = "pippo"><img src ="TMimagesAlt/addSession32.bmp" alt = "add session" border = "0"></a></td>
<td><a href = "http://www.google.it" target = "pippo"><img src ="TMimagesAlt/delete.bmp" alt = "delete" border = "0"></a></td>
<td><a href = "http://www.google.it" target = "pippo"><img src ="TMimagesAlt/proprieties.bmp" alt = "proprieties" border = "0"></a></td>
<td><a href = "userList.php" target = "pippo"><img src ="TMimagesAlt/user.bmp" alt = "user list" border = "0"></a></td>

</tr>

<table>
</td>
</tr>
<tr>
<td valign = "top">
<iframe src = "admin.php" width = "200" height = "400">
</iframe>
</td>
<td valign = "top">
<iframe src = "defaultFrameDX.php" width = "500" height = "400" name = "pippo">
</iframe>
</td>
</tr>
</table>
</div>
<div class="conts" id="t4Contents" style="width: 460; height: 88">
<p align="center" class="body"><b>Putting Information On The Tabs<br>
You can change any text, add tabs and much more.</b></p>
<p align="center" class="body"><b><font color="#000080">Continue to
Tab 5...</font></b></p>
</div>
<div class="conts" id="t5Contents" style="width: 460; height: 37">
<p align="center" class="body"><b>And so on..</b></p>
</div>
<div class="conts" id="t6Contents" style="width: 460; height: 37">
<p align="center" class="body"><b>And so on..</b></p>
</div>

<div class="conts" id="t7Contents" style="width: 460; height: 37">
<p align="center" class="body"><b>
Scroll a little down the page for instructions!</b></p>
</div>
<!-- Script end -->

</body>
</html>



ed ecco qui il codice interessato (copiato e incollato per mostrarvi che funziona)
N.B. non ditemi come altri forum...."'e' ma hai 2 form con lo stesso nome "----- Quello qua sotto e' solo il codice che ho usato sopra. Prendete solo la parte sotto, la metete in una pagina e vedrete che fa quello che il codice sopra non fa.



<script language = "javascript" type="text/javascript">

function change()
{

var select = document.theForm.dhcp.value;


if(select=="yes")
{

document.theForm.hostName.disabled = true;
document.theForm.ipAddress.disabled = true;
document.theForm.gateway.disabled = true;
document.theForm.dns1.disabled = true;
document.theForm.dns2.disabled = true;
document.theForm.macAdd.disabled = true;
document.theForm.subnet.disabled = true;
}
else
{

document.theForm.hostName.disabled = false;
document.theForm.ipAddress.disabled = false;
document.theForm.gateway.disabled = false;
document.theForm.dns1.disabled = false;
document.theForm.dns2.disabled = false;
document.theForm.subnet.disabled = false;
document.theForm.macAdd.disabled = false;
}
}
</script>

<form action = "" method = "post" name = "theForm">
<table cellspacing="5" cellpadding="5" border = "1" align = "center" width = "380" bgcolor="#ffffff">

<tr>
<td width = "150" align = "center"><img src="TMimagesAlt/net.bmp" border="0"></td>
<td>Ip config</td>
</tr>
<tr>
<td>Dhcp :</td>
<td>
<select name = "dhcp" onChange = "change();">
<option value = "no">no</option>
<option value = "yes">yes</option>

</select>
</td>
</tr>

<tr>
<td>Host Name:</td>
<td><input type = "text" name = "hostName"></td>
</tr>
<tr>
<td>IP Address:</td>
<td><input name="ipAddress" type="text"></td>
</tr>
<tr>
<td>Subnet Mask :</td>
<td><input name="subnet" type="text" ></td>
</tr>
<tr>
<td>Gateway :</td>
<td><input name="gateway" type="text" ></td>
</tr>
<tr>
<td>Mac Address :</td>
<td><input name="macAdd" type="text"></td>
</tr>

<tr>
<td>Dns primary :</td>
<td><input name="dns1" type="text" ></td>
</tr>
<tr>
<td>Dns secondary :</td>
<td><input name="dns2" type="text" ></td>
</tr>

<tr>
<td align = "center" colspan ="2">
<table cellspacing="5" cellpadding="5" align ="center">

<tr>
<td><input type="submit" value="OK"></td>
<td><input type="reset" value="Cancel"></td>
<td><input type="submit" value="Help"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>


Per favore aiutatemi
grazie

Offline lucasali

  • Moderatore
  • Post: 7493
errato funzionamento evento on Change su Select
« Risposta #1 il: 22 Novembre 2005 11:19:24 »
scusami la domanda ma questo codice funziona con un browser diverso da FF, visto che non hai menzionato nessun problema di compatibilità o altro...
se non funziona nemmeno con IE mi dispiace ma per te ma questo non è il posto giusta per imparare il JS, se vuoi nel topic "Modello di segnalazione al webmaster" trovi i link ad alcune guide tra cui anche quella a js
poi ti consiglio di rivolgerti a forum specifici, sicuramente torverai più persone che possono aiutarti.

ciao. Luca

Offline stiffa

  • Post: 12
errato funzionamento evento on Change su Select
« Risposta #2 il: 22 Novembre 2005 12:08:17 »
Questo va su explorer ma non su mozilla firefox....e visto che questo forum si chiama mozilla italia speravo..... Guarda...anche su altri forum non sono riusciti ad aiutarmi...non mi meraviglio che nessuno guardi sto post...
grazie cmq

Offline miki64

  • Moderatore
  • Post: 35823
errato funzionamento evento on Change su Select
« Risposta #3 il: 22 Novembre 2005 12:14:33 »
Citazione da: stiffa
..... Guarda...anche su altri forum non sono riusciti ad aiutarmi...non mi meraviglio che nessuno guardi sto post... grazie cmq

Beh, no...  finora  il tuo topic lo hanno letto altre 22 persone diverse, devi solo avere pazienza ed aspettare un utente più esperto di noi in queste cose.
Ciao.

Offline klades

  • Moderatore
  • Post: 5788
    • http://www.nic-nac-project.org/~kaosmos
Re: errato funzionamento evento on Change su Select
« Risposta #4 il: 22 Novembre 2005 12:28:27 »
Citazione da: stiffa

function change()
{
var select = document.theForm.dhcp.value;

if(select=="yes")
{
document.theForm.hostName.disabled = true;
document.theForm.ipAddress.disabled = true;
document.theForm.gateway.disabled = true;
document.theForm.dns1.disabled = true;
document.theForm.dns2.disabled = true;
document.theForm.macAdd.disabled = true;
document.theForm.subnet.disabled = true;
}
else
{

document.theForm.hostName.disabled = false;
document.theForm.ipAddress.disabled = false;
document.theForm.gateway.disabled = false;
document.theForm.dns1.disabled = false;
document.theForm.dns2.disabled = false;
document.theForm.subnet.disabled = false;
document.theForm.macAdd.disabled = false;
}
}

[/code]

Per favore aiutatemi
grazie

Consiglio: quando un javascript non ti funziona su Firefox, vai in Strumenti --> Console Javascript e troverai il motivo.
Il problema è nel modo in cui tu richiami l'oggetto, usi un modo che è tipico di IE e non standard e quindi non funziona su Firefox.
Come l'altra volta aggiungi al form l'id
Codice: [Seleziona]

<form action = "" method = "post" name = "theForm" id="theForm">

Poi sostituisci tutti i

document.theForm.

con

document.getElementById("theForm").

Dovrebbe funzionare in modo crossbrowser, perchè getElementById è un metodo standard e quindi universale, almeno con i browser moderni.

Offline stiffa

  • Post: 12
Re: errato funzionamento evento on Change su Select
« Risposta #5 il: 22 Novembre 2005 14:42:01 »
Posso dirti una cosa???

Sei un ...un ...un GRANDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE!!!!!!!

miticissimo.....ora mi va anche su mozilla....

piccolo appunto...la select la gestisco cosi quando nella funzione js acquisisco il suo valore selezionato.
var dhcp = document.getElementById("theForm").dhcp.options[document.getElementById("theForm").dhcp.selectedIndex].value ;

con questo va perfetta.

Grazie mille ....non hai idea di quanto stessi aspettando uno come te.

Grazie..


P.S. Gia che ci sei magari....mi dici come posso variare la segente cosa?
I campi quando selezioni "no" sulla select vengono messi disabled.
Mi piacerebbe che al posto di disablet vengano messi in grigetto e quando fai yes i campi (prima con un determinato value che mi arriva da php) divengano value vuoti....
Perche su IE me lo fa...mentre su mozilla non cambia il colore degli input....

Ovviamente sia su explorer che su mozilla.
Cmq non prob...mi va bene anche laasciarlo cosi.

ancora grazie mille

Offline stiffa

  • Post: 12
Re: errato funzionamento evento on Change su Select
« Risposta #6 il: 22 Novembre 2005 14:59:18 »
..

Offline flod

  • Amministratore
  • Post: 15057
    • http://www.flod.org
errato funzionamento evento on Change su Select
« Risposta #7 il: 23 Novembre 2005 19:52:13 »
Stiffa: leggi il messaggio di klades riguardo all'utilizzo di questo forum
http://forum.mozillaitalia.org/viewtopic.php?p=91453#91453

Altra cosa: non postare centinaia di righe di codice, metti online una pagina di esempio: chi è interessato potrà visualizzarla e verificare il problema.

0 Utenti e 1 Visitatore stanno visualizzando questo topic.