Question

is there a jquery plugin or is it relatively easy to do?

There is a text field where users will be entering an amount. I want the text field to show '$'..when users click on the text field then '$' will be gone.

No correct solution

OTHER TIPS

I recently asked a similar question, I chose to use the Watermark plugin.

I imagine something like:

$('#myInput').one("click", function() {
    $(this).val('');//empty the prefilled input
});

Check out Events/One. From the docs:

Binds a handler to one or more events to be executed once for each matched element.

This one clears the field unless a value has been entered and restores the label on blur if the field is empty:

<input type="text" name="amount" id="amount" value="$" />

  $("#amount").focus(function(){
    this.value = this.value == "$" ? '' : this.value;
  }).blur(function(){
    this.value = this.value || "$" ;
  });
<input name=Amount value=$100 type=text onfocus="removeDollar(this)" onblur="setDollar(this)">
<script>

function setDollar(e)
{
    e.value = '$' + e.value;
}

function removeDollar(e)
{
    e.value = e.value.substr(1);
}
</script>

That's just basic HTML & JS...

<input type="text" name="amount" id="amount" value="$" onFocus="clearText(this)"/>

function clearText(textField)
{
     if (textField.value == textField.defaultValue)
         textField.value = ""
 }

Note: I'm not that familiar with jQuery, so this was just a guess using HTML & JS. If it's not what you were looking for, sorry.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow