简体   繁体   中英

Showing 2nd Dropdown based on First drop down not working

I am a newbie learning web development. I am trying to create a simple form with two dropdowns. Based on first drop down second dropn down should be visible.

But it is not working :

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

 <div class="container">
    <div class="box">
    <form>
  <div class="ccms_form_element cfdiv_custom">

                <div class="col-md-4">
                    <label for="inputType">Input Type</label></div>
                <div class="col-md-8" style="font-size:16pt;">
                    <select id="inputType" required name="inputType" style="width:500px" onChange="ChangeDropdowns();">
                        <option value="">Select Type : Type Of You Want to Process</option>
                        <option value="text">Text  </option>
                        <option value="genome">Numbers</option>
                        <option value="chacha">Special Characters</option>
                    </select>
                </div>
            </div>
  </div>

   <div class="style-sub-1" id="dataType" style="display: none;" >
                <div class="col-md-4">
                    <label for="inputType">Data Type</label></div>
                <div class="col-md-8" style="font-size:16pt;">
                    <select id="data" required name="data" style="width:500px">
                        <option value="">Select Data Source : Where is your Data?</option>
                        <option value="text">Data is already in Server</option>
                        <option value="genome">Need to Upload the File</option>

                    </select>
                </div>
                  </div>

                    <div class="row">



<script>

function ChangeDropdowns() {  

$(".style-sub-1").show();
}

</script>
</body>

</html>

Can someone tell me what I am doing wrong here ?

Use the following, using JQuery to detect the change in first select - and include JQuery as Scott said

$( document ).ready(function() {
  $("#inputType").on('change', function (){
    $(".style-sub-1").show();
  });
});

It looks like you are trying to use jquery (the $ in your javascript code). However, you haven't specified the jquery script in your html.

Try adding this

<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.3.js"></script>

In between the head blocks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM