Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: Answers: Use Placeholder instead of Default

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98568

  • msr_lance
  • msr_lances 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>
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98580

  • msr_lance
  • msr_lances 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));
    }
});
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.116 Sekunden
Donation Image