1

In the below select filed populating values from mysqlDB. By default i am hiding the next two read only fields. I need to show the hided 2 fields when the value changes in the select field(irrespective of the value). I am not familiar with java script, i have tried with one script, but it is not working. Please support.

<select id ="name" name="name" class="form-control" required>
    <option value="" disabled selected>Choose Wallet</option>

    <?php
    //my query       
    echo '<option value="' . $row['group'] . '">' . $row['group'] . '</option>';//qry output to the select field

    ?>

</select>
<div  id ="hide" class="form-group hide">
    <div class="col-md-3 col-xs-12">
        <input id ="od" value="<?php echo $od ?>" class="form-control" readonly/>
        <input id="bal" value="<?php echo $bal ?>" class="form-control" readonly/>
    </div>
</div>
<script type="text/javascript">
$("#name").change(function () {
$("#hide").removeClass('hide');
});
</script>

4 Answers 4

3

Please try this

<select id ="name" name="name" class="form-control" required onChange="showTextBox()">

and add this function

function showTextBox(){
    $("#hide").removeClass('hide');
}

OR

$(document).ready(function(){
    $("#name").change(function () {
        $("#hide").removeClass('hide');
    });
})

;

Sign up to request clarification or add additional context in comments.

Comments

1

.show() and .hide() method to hide and and show particular elements as per their name suggests

and you can use the " on " event so that it can work on even you dynamically add the options to the select tag by using jquery or javascript.

// or want to use by adding and removing class so you can use as below.
 
$(document).ready(function(){
    $("#name").on('change',(function () {
        $("#hide").removeClass('hide');
    });
});

Comments

0

You should code:

<script type="text/javascript">
$(function(){
    $("#name").change(function () {
      $("#hide").removeClass('hide');
    });
});
</script>

2 Comments

sorry, its not working. I have applied the above provided script, still on changing the value in the select field, the next two fields are not displaying.
Thanks to all for the help.
0

you can use $(".hide").show(); instead of $("#hide").removeClass('hide');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.