Dima Dima - 1 year ago 63
jQuery Question

How to insert a field after check the value of a field

I am searching for a way to insert one or more fields into HMTL after checking the value from a other field. Here is my HTML:

<select id="status" name="status">
<option value="1" style="background-color: #cdeb8e">freigegeben</option>
<option value="2" style="background-color: red">gesperrt</option>
<option value="3" style="background-color: yellow">Rückfrage erforderlich</option>
<option value="4" style="background-color: yellow">Muster</option>

status > 1
I want to add
<input type="text" />
after the
. How can I do that?

Kld Kld
Answer Source

You can check after the select changes and show/hide the input according to the selected value.

$('#status').change(function() {
  if ($(this).val() > 1) {
  } else {
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<select id="status" name="status">
  <option value="1" style="background-color:#cdeb8e">freigegeben</option>
  <option value="2" style="background-color:red">gesperrt</option>
  <option value="3" style="background-color:yellow">Rückfrage erforderlich</option>
  <option value="4" style="background-color:yellow">Muster</option>

<input type="text" style="display:none;" id="myInput" />

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download