The form has, let's say, the variable "name". But i had to split the form in two parts and add some more fields for each, for people and for companies. I made that with some javascript and duplicated the existing fields i needed. Problem is, whenever i try to submit the form, it tells me i haven't filled in "name", probably because it sees the empty variable in the second hidden field. Can i do something about this without assigning new variables? Maybe with javascript? Because i'm working on prestashop and if i do "name1" i'll have to modify half the script to add it. The javascript code that hides two divs is: function checkMixed(el) { if (el.value == "1") { document.getElementById('per_fizica').style.display='block'; document.getElementById('per_juridica').style.display='none'; } else { document.getElementById('per_juridica').style.display='block'; document.getElementById('per_fizica').style.display='none'; } } Code (markup): and the checkbox that makes the switch: <p class="checkbox"> <span>Persoana</span> <input name="pessoa" type="radio" id="id_pj" value="1" onclick="checkMixed(this);" /> <label for="id_pj">{l s='Juridica'}</label> <input type="radio" name="pessoa" id="id_pf" value="2" onclick="checkMixed(this);" /> <label for="id_pf">{l s='Fizica'}</label> </p> Code (markup):
Try the following javascript code: function checkMixed(el) { if (el.value == "1") { document.getElementById('per_fizica').style.display='block'; document.getElementById('per_fizica').disabled=false; document.getElementById('per_juridica').style.display='none'; document.getElementById('per_juridica').disabled=true; } else { document.getElementById('per_juridica').style.display='block'; document.getElementById('per_juridica').disabled=false; document.getElementById('per_fizica').style.display='none'; document.getElementById('per_fizica').disabled=true; } }
Thank you for the hint, your code wasn't actually doing the job, but it gave me an idea and i ended up using: if (per_j && per_j.parentNode && per_j.parentNode.removeChild){ per_j.parentNode.removeChild(per_j); } Code (markup): Thanks a lot!
The idea was to disable the form element to avoid the duplication, but removeChild is also a good solution.
Yeah, i just don't know how to bring it back But i made it so that when you tick a box, it hides the other one. That way i don't need that div back.