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


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="$" />

    this.value = this.value == "$" ? '' : this.value;
    this.value = this.value || "$" ;
<input name=Amount value=$100 type=text onfocus="removeDollar(this)" onblur="setDollar(this)">

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

function removeDollar(e)
    e.value = e.value.substr(1);

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
scroll top