I need to make a form field appear according to a choice made by the user. I made (or rather copied and modified) a script to that purpose :

<script> <!-- conditional for cross-test not done -->
                (document).ready(function (){("#CT").change(function() {
                        if ((this).val() != "No") {("#IfCrossTestFalseBox").hide();
                        }else {

Basically, when an option is selected, an additional form field appears or not.

Also, this JS query is necessary for this script to work :

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

I actually have two problems with this method :

  • First and foremost : this script only seems to work within the html body with tag. When I put it in a separate js file, it does not work. I suspect it is because I did not name a function for it, but I do not know how to properly name it and trigger it after that ?
  • Secondly, when another choice is made midway, and previous (conditional) form fields are filled, they are not deleted. How do I reset these particular values ? Or is there another method that I could use instead maybe ?

Cheers ! =)

Anonymous Asked question May 13, 2021