Hi guys, I'm new to javascript and I need to show/hide some elements based on the value of a radio button. The little extra is that when I first load the page I set a default value for the radio button and I show the appropriate elements. If the user change the value of the radio button, another elements should be showed. Then the user can submit the form and it takes it to a verification page. My problem is that if the user goes back to the first page, the elements showed are the ones for the default value. Here is the code I'm using:
var sTipoSolicitud = "Transferencia";
function TipoSolicitud(dato)
{
sTipoSolicitud = dato;
/* Hides all elements */
Beneficiario.style.display = "none";
BancoIntermediario.style.display = "none";
BancoBeneficiario.style.display = "none";
InfoAdicional.style.display = "none";
beneficiario_cheque.style.display = "none";
cuenta_deposito.style.display = "none";
if (dato=="Transferencia")
{
/* Shows elements for Transferencia */
Beneficiario.style.display = "";
BancoIntermediario.style.display = "";
BancoBeneficiario.style.display = "";
InfoAdicional.style.display = "";
}
else
if (dato=="Deposito")
cuenta_deposito.style.display = "";
else
beneficiario_cheque.style.display = "";
}
Then on the radio button definition, this is what I have:
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" value=http://www.webdeveloper.com/forum/archive/index.php/"Transferencia" checked name="TIPO_SOLICITUD" tabindex="1">Transfer
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" name="TIPO_SOLICITUD" value="Deposito" tabindex="3">Deposit
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" name="TIPO_SOLICITUD" value="Cheque" tabindex="2">Check
I know that since I'm initializing sTipoSolicitud = "Transferencia" that's why it is using the default to show/hide the elements and what I need is a way to initialize it to whatever the user has chosen before!
As I said, I'm new to javascript and I'd really appreciate any help.
Thank you very much,
Karla
var sTipoSolicitud = "Transferencia";
function TipoSolicitud(dato)
{
sTipoSolicitud = dato;
/* Hides all elements */
Beneficiario.style.display = "none";
BancoIntermediario.style.display = "none";
BancoBeneficiario.style.display = "none";
InfoAdicional.style.display = "none";
beneficiario_cheque.style.display = "none";
cuenta_deposito.style.display = "none";
if (dato=="Transferencia")
{
/* Shows elements for Transferencia */
Beneficiario.style.display = "";
BancoIntermediario.style.display = "";
BancoBeneficiario.style.display = "";
InfoAdicional.style.display = "";
}
else
if (dato=="Deposito")
cuenta_deposito.style.display = "";
else
beneficiario_cheque.style.display = "";
}
Then on the radio button definition, this is what I have:
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" value=http://www.webdeveloper.com/forum/archive/index.php/"Transferencia" checked name="TIPO_SOLICITUD" tabindex="1">Transfer
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" name="TIPO_SOLICITUD" value="Deposito" tabindex="3">Deposit
<input type="radio" OnClick="javascript:TipoSolicitud(this.value);" name="TIPO_SOLICITUD" value="Cheque" tabindex="2">Check
I know that since I'm initializing sTipoSolicitud = "Transferencia" that's why it is using the default to show/hide the elements and what I need is a way to initialize it to whatever the user has chosen before!
As I said, I'm new to javascript and I'd really appreciate any help.
Thank you very much,
Karla