Pronto, aqui está, acredito que seja o que deseja!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Compara radios com texts </title>
<script>
function liberaProdutos(){
// variável formuário
var form = document.nm_frmPedido;
// caminha pelo formulário
for(var i=0; i < form.length; i++){
if (form[i].name == 'nm_txtQtd'){
// libera text para edição
form[i].disabled = false;
}
}
};
function verificaValores(o){
// variáveis do formuários
var form = document.nm_frmPedido;
var radios = form.nm_rdoPacote;
var total = form.nm_txtQtdTotal;
// variável booleana para verificação de seleção de pacote
var blnRadio = false;
// variáveis inteiras para cálculos
var valorTotal = new Number(0);
var valorPacote = new Number(0);
// caminha pelo formulário
for(var i=0; i < form.length; i++){
// verifica se o objeto do form e o txtQtd
if (form[i].name == 'nm_txtQtd'){
// atribui um valor numerico a variavel valorAux
valorAux = new Number(form[i].value);
// soma os valores dos texts de quantidade de produtos
valorTotal += valorAux;
}
// pega a quantidade do pacote escolhido
if (form[i].name == 'nm_rdoPacote' && form[i].checked == true){
// atribui um valor escolhido a variavel valorPacote
valorPacote = new Number(form[i].value);
// inverte a falg
blnRadio = true;
}
}
// verifica a seleção de um pacote
if (blnRadio){
// verifica a quantidade de produtos quanto ao pacote
if (valorTotal <= valorPacote){
total.value = valorTotal;
}
else{
alert('Valores de produtos excedem o numero do pacote!');
o.value = '';
o.focus();
}
}
else {
alert('É obrigatória a seleção de um pacote!');
}
};
</script>
</head>
<body>
<form name="nm_frmPedido" method="post" action="../verpedido.php">
<label>Pacotes: </label> <br />
<input type="radio" name="nm_rdoPacote" value="400" id="400" onclick="liberaProdutos();" /> <label>400</label> <br />
<input type="radio" name="nm_rdoPacote" value="500" id="500" onclick="liberaProdutos();" /> <label>500</label> <br />
<input type="radio" name="nm_rdoPacote" value="600" id="600" onclick="liberaProdutos();" /> <label>600</label> <br />
<input type="radio" name="nm_rdoPacote" value="700" id="700" onclick="liberaProdutos();" /> <label>700</label> <br /><br />
<label>Produtos/Quantidade: </label> <br />
Batata Frita: <input type="text" name="nm_txtQtd" size="2" maxlength="3" onblur="verificaValores(this);" disabled="disable"/> <br />
Crepe: <input type="text" name="nm_txtQtd" size="2" maxlength="3" onblur="verificaValores(this);" disabled="disable"/> <br />
Pizza: <input type="text" name="nm_txtQtd" size="2" maxlength="3" onblur="verificaValores(this);" disabled="disable"/> <br />
Hamburguer: <input type="text" name="nm_txtQtd" size="2" maxlength="3" onblur="verificaValores(this);" disabled="disable"/> <br /><br />
Total: <input type="text" name="nm_txtQtdTotal" size="2" readonly value="0"/>
</form>
</body>
</html>
A a parte que realmente lhe interessa está dentro da função "verificaValores", tem algumas firulagens que adaptei do legado!
Caracas, esses legados!
Edição feita por: Renan L. Queiroz, 29/12/2009, 10:19.