I have the following JavaScript code, used to replace the code contained in a <div>
of the page with a portion from another:
function ReplaceContentInContainer(etiqueta) {
var container = document.getElementById('contenedor');
if (etiqueta="esTransportista") {
container.innerHTML = document.getElementById('transportista').innerHTML;
} else if (etiqueta="esCargador") {
container.innerHTML = document.getElementById('cargador').innerHTML;
}
}
Then I call it from the page with the following code:
<input type='radio' name='esTransportista' id='esTransportista' value='1' onclick="javascript:ReplaceContentInContainer(esTransportista);">Es transportista <br />
<input type='radio' name='esTransportista' id='esCargador' value='0' onclick="javascript:ReplaceContentInContainer(esCargador);" checked>Es cargador <br />
And, finally, I have three <div>'s
in my page, one to display the information < div id='contenedor'>< /div>
and the other two containing the code to be displayed in this id='contenedor'
I mentioned (being them <div id='transportista'>bla bla bla< /div>
and < div id='cargador'>bla2 bla2 bla2< /div>
).
The problem I face is that the JavaScript code seems to work just once. It changes the content of 'contenedor' the first time I check one of the radio buttons, but if I check the other one the JavaScript doesn't work anymore.
Is there any way I could make the JavaScript code work every time I click on any of the radio buttons?
I've been googling and most of the results I surfed refer to jQuery and bounding to elements that are vanished, but this is not my case, as far as I know...