Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Answers: Use Placeholder instead of Default

Answers: Use Placeholder instead of Default 1 year 2 months ago #98568

  • msr_lance
  • msr_lance's Avatar
Thanks, that's useful to know!

For what it's worth, I couldn't get my latest code and your {SGQ} to work at the same time (when both were included).

I don't have a default defined for this question, so I'd assume 'xxxx' would be set as the 'value', but instead it's empty.
$(document).ready(function() {
 
var specialPrefix = "***";
 
var inputs = document.getElementsByTagName("input");
for (x=0;x<=inputs.length;x++){
   id = inputs[x].getAttribute("id");
   if(id.indexOf("answer")==0){
      var value = $('#'+id).attr('value');
      if (value.lastIndexOf(specialPrefix, 0) == 0){
         $('#'+id)
         .attr('value', '')
         .attr('placeholder', value.substring(specialPrefix.length));
      }
   }
}
 
 
var SGQ = '{SGQ}';
$('#answer'+SGQ).attr('value', 'xxxx');
 
}); 
</script>
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98580

  • msr_lance
  • msr_lance's Avatar
Here's a revised version which uses jQuery's attributeStartsWith selector to generically find all elements with 'id' starting with "answer". Now we handle input, text area, etc.

var specialPrefix = "***";
 
$('[id^="answer"]').each(function() {
    var value = $(this).attr('value');
    if (value.lastIndexOf(specialPrefix, 0) == 0){
         $(this)
         .attr('value', '')
         .attr('placeholder', value.substring(specialPrefix.length));
    }
});
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.093 seconds
Donation Image