tags:

views:

142

answers:

5

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.

+1  A: 

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

Pool
A: 
<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>
RedFilter
inlining script events....not how jquery is meant to be
redsquare
This is meant to show underlying mechanics - attaching events programmatically can be a bit abstract, especially if you get into external js files. I find this code self-evident, and no external libraries needed. Going from this to jQuery is a smaller leap than if you skip this step.
RedFilter
+1  A: 

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.

karim79
A: 

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.

Walker Argendeli
+1  A: 

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 || "$" ;
  });
tom