0

i am making a form that has a date field using textfield, i want my date field to have a label format inside the textfield, here's the picture: enter image description here after clicking on the textfield the format will be erased and the hyphen will remain like this picture: enter image description here i already made the code for the label format, here's my code:

<input type="text" name="date" value="DD_MM_YYYY" id="date" style="width:180px" onclick="if(this.value=='DD_MM_YYYY'){this.value=''}"  />
</p>

My problem now is the hypen that will remain after clicking the textfield.

Anyone knows how to do that?

Thanks in advance.

1
  • 1
    No need to reinvent the wheel, I'd suggest using a mask plugin for your use-case, even though I'd personally prefer a datepicker one. Commented Jan 10, 2013 at 2:43

2 Answers 2

1

I would recommend Masked Input Plugin.
http://digitalbush.com/projects/masked-input-plugin/

You can define your own type of mask by using the code:

jQuery(function($){
   $("#myinput").mask("99-99-9999",{placeholder:" "});
});

Then you can define a placeholder to the input:

<input id='myinput' placeholder='dd-mm-yyyy'>
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the placeholder attribute.

<input placeholder="  -  -    " value="DD-MM-YYYY" />

You can continue to set the value to nothing when the element is focused. On blur set the value back to DD-MM-YYYY.

Note that this attribute isn't supported by all browsers.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.