here are some thoughts
rude solution with jquery
HTML
<input type="text" id='myinput' value ="my text">
JQuery
var orginal_text = $('#myinput').val(); var regular_expression = '/^' + orginal_text +'/' ; $('#myinput').keyup(function(){ var current_text = $('#myinput').val(); if(current_text.match('^' + orginal_text +'') == null){ $('#myinput').val(orginal_text + ' ' +current_text ) } })
http://jsfiddle.net/e5EDY/
with css
HTML
<input type="text" id='my_sticky_text' value ="my text" readonly='readonly'> <input type="text" id='myinput' value ="my text">
CSS
#my_sticky_text{ position:absolute; left : 0px; } #myinput{ position:absolute; left : 50px; border-left:none; }
http://jsfiddle.net/kaf4j/
to get the value
HTML
<input type="text" id='my_sticky_text' value ="my text" readonly='readonly'> <input type="text" id='myinput' value ="my text"> <br> <hr> <button id='getval'>get value</button>
CSS
#my_sticky_text{ position:absolute; left : 0px; } #myinput{ position:absolute; left : 50px; border-left:none; }
JQuery
$('#getval').click(function(){ var sticky_text = $('#my_sticky_text').val(); var user_text = $('#myinput').val(); alert (sticky_text + ' ' + user_text) })
http://jsfiddle.net/YsNMQ/
what do we get from all this?! .. you just canโt do what you want in a beautiful way .. and I canโt imagine the situation when I want to do it.
alternatives
1 - in the text box label, place the permanent text.
2 - when the user submits the form, captures the value of the text field and adds text to it.
3- add help to the user that this entry should be as follows (for example: mytext-yourtext)
Hussein nazzal
source share