0

So... I have a list of input boxes in my form... no labels, just placeholder texts.

lets say I have a text input field for an email...

and that the value of this text is ruby@rails.com

I would like to display: (email) after that string...

enter image description here

(only when input is blured, when input is focused, than the label shouldn't be there)...this I know how to do it...

the only problem is, that I don't know how to calculate the witdh of the actual text inside the input box, so I can display the label right beside it (another element positioned absolutely of course)

Any ideas?

========================================================== edit

so, I am using something like this in html markup

<input type="text" name="my_field" value="" data-fixed-placeholder="(email)" placeholder="email">

and then I am using jQuery to check if data fixed-placeholder is present... and display it...

so something like this (just semantically... the code is obviously not like that)

$("[data-fixed-placeholder]").on("focus", function(e){
    //hide the fixed placeholder
}).on("blur", function(e){
    //show the palceholder
   //1. check if there is no text inside... then don't show it (the original placeholder is still visible)
   //2. if there is text, calculate how wide it is
   //3. wrap input box in div, make it position relative, append another div inside with the text from fixed-placeholder
   //4. position this text next to the actual text in the input box
});

Hope this helps you to help me better.

DS_web_developer
  • 3,622
  • 13
  • 52
  • 83

0 Answers0