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.
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.
I recently asked a similar question, I chose to use the Watermark plugin.
<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>
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.
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.
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 || "$" ;
});