Se devi eseguire un controllo generico sui due valori presi assieme, puoi usare l'operatore ^ (XOR) che copre tutte le casistiche da te indicate, secondo questa tabella della verità:
A
|
B
|
A XOR B
|
0 |
0 |
0 |
0 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
0 |
Un esempio pratico:
codice:
<!DOCTYPE HTML>
<html>
<head>
<title>Esempio</title>
<meta charset="utf-8">
<script type="text/javascript">
function controlloCampi(){
var codice = form1.codice.value;
var valore = form1.valore.value;
if (codice != "" ^ valore > 0){
alert('errore')
} else {
alert('tutto ok')
}
}
</script>
</head>
<body>
<form id="form1">
codice <input id="codice">
<br>valore <input id="valore">
<br><br><input type="button" value="CONTROLLA" onclick="controlloCampi()">
</form>
</body>
</html>