Originariamente inviato da cavicchiandrea
Prova cosi:
codice:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script>
function cambia(){
if(document.modulo.modifica.checked){
document.modulo.sconto.readOnly='';
document.modulo.prezzo.readOnly=true;
}else{
document.modulo.prezzo.readOnly='';
document.modulo.sconto.readOnly=true;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento senza titolo</title>
</head>
<body>
<form action="pagina.html" method="post" name="modulo">
<input type="text" name="sconto" value="bello" readonly="true">
<input type="text" name="prezzo" value="brutto">
<input type="checkbox" name="modifica" onClick="cambia();" value="1">
</form>
</p>
</body>
</html>
Ciao ho utilizzato lo stesso metodo per una cosa....benissimo. Ti spiego questa è la mia situazione Javascript:
codice:
function IsNumeric(strString)
// check for valid numeric strings
{
var strValidChars = "0123456789.-";
var strChar;
var blnResult = true;
if (strString.length == 0) return false;
// test strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++)
{
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1)
{
blnResult = false;
}
}
return blnResult;
}
function checkinputPR()
{
if (document.newitem.textprezzo.value.length == 0)
{
alert("Inserisci un valore nel campo PREZZO");
}
else if (IsNumeric(document.newitem.textprezzo.value) == false)
{
alert("Attenzione - Campo numerico!");
}
}
<script language="JavaScript">
function saveall()
{
if (IsNumeric(document.newitem.textprezzo.value) == true)
{
document.getElementById("newitem").submit()
}
}
</script>
<script language="javascript">
function disableprice(){
if(document.newitem.checkprice.checked){
document.newitem.textprezzo.readOnly=false;
}else{
document.newitem.textprezzo.readOnly=true;
}
}
</script>
Tenendo conto degli ultimi due script del codice......sullo stesso campo input "textprezzo" ho un altro script che mi forza nel mettere caratteri e per lo piu devono essere numerici, al suo interno .... Quando tolgo il check il campo input si disabilita ma lasciando poi il suo valore vuoto fa scattare l'altro controllo che non permette al pulsante "Salva" di salvare. Come faccio a dirgli di eseguire il controllo su quel campo solo se l'elemento input è abilitato ??