Urgente: deshabilitar y habilitar botón

Hice la prueba en un php, y tiene razón si funciona el código tal y comolo tengo y al recargar ya no aparece seleccionado ningún radiobutton y gracias también por el código que me envío lo probé y si funciono, pero ahora tengo el siguiente problema, lo que quiero hacer es que aparte de que cuando se seleccione un radiobutton se habilite su lista correspondiente también se habilite el botón Siguiente pero siempre y cuando también se seleccione de la lista un valor de la lista y no un valor nulo como puede ser este "----" y que si el usuario cambia de radiobutton se vuelva a deshabilitar el botón Siguiente y se habilite de nuevo cuando el usuario seleccione una opción valida de la lista.
Ya logre que el botón Siguiente se habilite cuando el usuario seleccione una opción valida de la lista, pero cuando cambio de radiobutton no se deshabilta el botón Siguiente sino que se deshabilita cuando comienzo a seleccionar valores de la lista no se cual sea el error en mi código.
Otra cosa que quisiera saber es como hacer que cuando el usuario cambia de radiobutton y en la lista que se queda deshabilitada se quede con el valor inicial ( en este caso "----") y no con el valor que se había seleccionado antes de deshabilitarlo por cambiar de radiobutton.
Este es el código de mi programa:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script>
function EstableceEstado1() {
if (document.form1.radiob[1].checked) {
//document.form1.select1.selectedIndex = -1
document.form1.select1.disabled = true
}
else
if (document.form1.radiob[0]) {
document.form1.select1.disabled = false
}
if (document.form1.radiob[0].checked) {
//document.form1.select2.selectedIndex = -1
document.form1.select2.disabled = true
}
else
if (document.form1.radiob[1]) {
document.form1.select2.disabled = false
}
}
function activar(formulario) {
if(document.form1.select1 == "---------")
formulario.Submit.disabled = true
else
formulario.Submit.disabled = false
if(document.form1.select2 == "---------")
formulario.Submit.disabled = true
else
formulario.Submit.disabled = false
}
function desactivar(formulario) {
if(document.form1.radiob[0].checked){
formulario.Submit.disabled = true
}
if(document.form1.radiob[1].checked){
formulario.Submit.disabled = true
}
}
function QuitaFoco1() {
if(document.form1.radiob[0].checked)
document.form1.select2.blur()
if(document.form1.radiob[1].checked)
document.form1.select1.blur()
}
function Deshabilita1() {
if(document.form1.radiob[0]){
//document.form1.select1.selectedIndex = -1
document.form1.select1.disabled = true
}
if(document.form1.radiob[1]){
//document.form1.select2.selectedIndex = -1
document.form1.select2.disabled = true
}
}
window.onload = Deshabilita1;
if (document.captureEvents) { //N4 requiere invocar la funcion captureEvents
document.captureEvents(Event.LOAD)
}
</script>
<body>
<form name="form1" method="post" action="">
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Pera
<select name="select1[]" id="select1" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option>---------</option>
<option>uno</option>
<option>dos</option>
</select>
</p>
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Manzana
<select name="select2[]" id="select2" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option selected>---------</option>
<option>tres</option>
<option>cuatro</option>
</select>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" value="Siguiente" disabled >
</p>
</form>
</body>
</html>
Ojala y pueda ayudarme.

2 respuestas

Respuesta
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script>
function EstableceEstado1()
{
if (document.form1.radiob[1].checked)
{
document.form1.select1.disabled = true
}
else if (document.form1.radiob[0]) {
document.form1.select1.disabled = false
document.form1.select1.focus();
}
if (document.form1.radiob[0].checked) {
document.form1.select2.disabled = true
document.form1.select1.focus();
}
else if (document.form1.radiob[1]) {
document.form1.select2.disabled = false
document.form1.select2.focus();
}
if((document.form1.select1.disabled && document.form1.select2.value != "") || (document.form1.select2.disabled && document.form1.select1.value!=""))
document.form1.Submit.disabled = false
else
document.form1.Submit.disabled = true
}
function activar(formulario)
{
if((document.form1.select1.disabled && document.form1.select2.value != "") || (document.form1.select2.disabled && document.form1.select1.value!=""))
document.form1.Submit.disabled = false
else
document.form1.Submit.disabled = true
}
function desactivar(formulario) {
if(document.form1.radiob[0].checked){
formulario.Submit.disabled = true
}
if(document.form1.radiob[1].checked){
formulario.Submit.disabled = true
}
}
function QuitaFoco1() {
if(document.form1.radiob[0].checked)
document.form1.select2.blur()
if(document.form1.radiob[1].checked)
document.form1.select1.blur()
}
function Deshabilita1() {
if(document.form1.radiob[0]){
//document.form1.select1.selectedIndex = -1
document.form1.select1.disabled = true
}
if(document.form1.radiob[1]){
//document.form1.select2.selectedIndex = -1
document.form1.select2.disabled = true
}
}
window.onload = Deshabilita1;
if (document.captureEvents) { //N4 requiere invocar la funcion captureEvents
document.captureEvents(Event.LOAD)
}
</script>
<body>
<form name="form1" method="post" action="">
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Pera
<select name="select1[]" id="select1" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option value="">---------</option>
<option value="uno">uno</option>
<option value="dos">dos</option>
</select>
</p>
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Manzana
<select name="select2[]" id="select2" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option value="" selected>---------</option>
<option value="tres">tres</option>
<option value="cuatro">cuatro</option>
</select>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" value="Siguiente" disabled >
</p>
</form>
</body>
</html>
¿Aun necesitas el código?, lo voy a revisar y te lo envío.
Eduardo Valenzuela
Lima - Peru
Respuesta
1
Ya está con la nueva mejora, aunque faltaría depurarlo un pelín. Saludos.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Documento sin título</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<script>
function EstableceEstado1() {
if (document.form1.radiob[1].checked) {
//document.form1.select1.selectedIndex = -1
document.form1.select1.disabled = true
}
else
if (document.form1.radiob[0]) {
document.form1.select1.disabled = false
}
if (document.form1.radiob[0].checked) {
//document.form1.select2.selectedIndex = -1
document.form1.select2.disabled = true
}
else
if (document.form1.radiob[1]) {
document.form1.select2.disabled = false
}
}
function activar(formulario) {
if(document.form1.select1.options[document.form1.select1.selectedIndex].text.indexOf("----")!=-1 && document.form1.radiob[0].checked){
formulario.Submit.disabled = true;
return;
}
if(document.form1.select2.options[document.form1.select2.selectedIndex].text.indexOf("----")!=-1 && document.form1.radiob[1].checked){
formulario.Submit.disabled = true;
return;
}
if(document.form1.select1 == "---------")
formulario.Submit.disabled = true
else
formulario.Submit.disabled = false
if(document.form1.select2 == "---------")
formulario.Submit.disabled = true
else
formulario.Submit.disabled = false
}
function desactivar(formulario) {
if(document.form1.radiob[0].checked){
formulario.Submit.disabled = true
}
if(document.form1.radiob[1].checked){
formulario.Submit.disabled = true
}
}
function QuitaFoco1() {
if(document.form1.radiob[0].checked)
document.form1.select2.blur()
if(document.form1.radiob[1].checked)
document.form1.select1.blur()
}
function Deshabilita1() {
if(document.form1.radiob[0]){
//document.form1.select1.selectedIndex = -1
document.form1.select1.disabled = true
}
if(document.form1.radiob[1]){
//document.form1.select2.selectedIndex = -1
document.form1.select2.disabled = true
}
}
window.onload = Deshabilita1;
if (document.captureEvents) { //N4 requiere invocar la funcion captureEvents
document.captureEvents(Event.LOAD)
}
function init(){
Deshabilita1();
document.form1.radiob[0].checked=false;
document.form1.radiob[1].checked=false;
}
</script>
<body onload="init()">
<form name="form1" method="post" action="">
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Pera
<select name="select1[]" id="select1" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option>---------</option>
<option>uno</option>
<option>dos</option>
</select>
</p>
<p>
<input name="radiob" type="radio" value="" onclick="EstableceEstado1()" onChange="desactivar(this.form)">
Manzana
<select name="select2[]" id="select2" onFocus="QuitaFoco1()" onChange="activar(this.form)">
<option selected>---------</option>
<option>tres</option>
<option>cuatro</option>
</select>
</p>
<p> </p>
<p>
<input type="submit" name="Submit" value="Siguiente" disabled >
</p>
</form>
</body>
</html>

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas