javascript - Textarea placeholder with a checkbox -


i'm trying change placeholder of textarea press of checkbox button. can't change.

to clear, i'm trying set placeholder not value.

my textarea:

<textarea name="problem" id="problem" rows="3" class="form-control" cols="45" placeholder="describe ticket reason in few words possible."></textarea>  

my javascript:

<div class="onoffswitch">                 <input type="checkbox" onchange="changeplh()" name="onoffswitch" class="onoffswitch-checkbox" value="1" id="myonoffswitch" checked>                     <label class="onoffswitch-label" for="myonoffswitch">                         <span class="onoffswitch-inner"></span>                         <span class="onoffswitch-switch"></span>                     </label>                  <script>                     function changeplh(){                         debugger;                         var sel = document.getelementbyid("myonoffswitch");                         var textbx = document.getelementbyid("problem");                         var indexe = sel.selectedindex;                          if(indexe == 0) {                             $("#problem").val('');                             $("#problem").prop("placeholder", "age");                      }                            if(indexe == 1) {                              $("#problem").val('');                             $("#problem").prop("placeholder", "name");                     }                     }                            </script>             </div> 

what need - checkbox button changes placeholder of textarea 2 different options. ex: click once, says "age", click again says "name", click again says "age" etc.

your code little bit messy (for example, have no #problem in code) created simple demo of changing placeholder.

$('#problem').change(function() {    $('textarea').attr('placeholder', $(this).is(':checked') ? 'name' : 'age');  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <textarea class="form-control" style="height:150px" name="techproblem" placeholder="describe issue in few words possible."></textarea>    <label><input type="checkbox" id="problem" /> change placeholder</label>


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -