A brief explanation on the code below:
On JSFiddle my code work but whenever I transfer it on my website I get the Uncaught: TypeError. Please provide your suggestions to resolve TypeError.
$('#myButton').on('click', function() { var op1 = document.getElementById("op1").value; alert(op1); var op2 = document.getElementById("op2").value; alert(op2); if (op1 =='a'){ $("#op2").html("<select id='op2'><option value='800'>800</option><option value='3000'>3000</option></select>"); } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <select id="op1" > <option value="a">a</option> <option value="b">b</option> <option value="all">all</option> </select> <select id="op2"> <option value="1">1</option> <option value="11">11</option> </select> <input type="submit" value="button" id="myButton" class="buttonClass" />
Your script needs to be placed in the head tag <head></head>
and must be loaded before your script.
<!DOCTYPE html>
<html>
<head>
<title>Title of the document</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="yourLocalPath.js"></script>
</head>
<body>
<select id="op1" >
<option value="a">a</option>
<option value="b">b</option>
<option value="all">all</option>
</select>
<select id="op2">
<option value="1">1</option>
<option value="11">11</option>
</select>
<input type="submit" value="button" id="myButton" class="buttonClass" />
</body>
</html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.