Krishh Krishh - 1 year ago 305
jQuery Question

Change Placeholder Text using jQuery

I am using a jQuery placeholder plugin( I need to change the placeholder text with the change in dropdown menu. But it is not changing. Here is the code:

$(function () {
$('input[placeholder], textarea[placeholder]').placeholder();
$('#serMemdd').change(function () {
var k = $(this).val();
if (k == 1) {
$("#serMemtb").attr("placeholder", "Type a name (Lastname, Firstname)").placeholder();
else if (k == 2) {
$("#serMemtb").attr("placeholder", "Type an ID").placeholder();
else if (k == 3) {
$("#serMemtb").attr("placeholder", "Type a Location").placeholder();

My Html:

<div class="filterbox">
<select name="ddselect" id="serMemdd">
<option value="1" selected="selected">Search by Name</option>
<option value="2">Search by ID</option>
<option value="3">Search by Location</option>
<input id="serMemtb" type="text" style="width: 490px" placeholder="Type a name (Lastname, Firstname)" />
<input id="seMemBut" type="button" value="Search" />

Can anyone figure this out?

Answer Source
  $('form').find("input[type=textarea], input[type=password], textarea").each(function(ev)
      if(!$(this).val()) { 
     $(this).attr("placeholder", "Type your answer here");

Copy and paste this code in your js file, this will change all placeholder text from whole site.

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