The Little Guy Posted January 28, 2012 Share Posted January 28, 2012 I am using jquery, and I would like to force the first text in the text box to be http:// I would like it so a user can not delete that text. any suggestions on how to keep it there? I would use keypress(), but the backspace isn't supported in Chrome. keydown deletes the last "/" keyup deletes the last "/" then adds it back. Here is the code (replace keypress with keyup/keydown): $("#domainTest").keypress(function(){ if(!$(this).val().match(/^http:\/\//)){ $(this).val("http://"); return false; } }); So, what can I do? Quote Link to comment https://forums.phpfreaks.com/topic/255917-backspace-keypress-not-supported-in-chrome/ Share on other sites More sharing options...
joel24 Posted January 28, 2012 Share Posted January 28, 2012 why not use PHP to add it after form submission? and have the input bg set to an image of the text 'http://' ? or use jquery's change() function Quote Link to comment https://forums.phpfreaks.com/topic/255917-backspace-keypress-not-supported-in-chrome/#findComment-1311855 Share on other sites More sharing options...
The Little Guy Posted January 28, 2012 Author Share Posted January 28, 2012 why not use PHP to add it after form submission? and have the input bg set to an image of the text 'http://' ? Because it is just for a visual purpose, php will take out http/https, but I do like the image idea... Quote Link to comment https://forums.phpfreaks.com/topic/255917-backspace-keypress-not-supported-in-chrome/#findComment-1311859 Share on other sites More sharing options...
kicken Posted January 28, 2012 Share Posted January 28, 2012 Or just put it in front of the text box. eg: <p>http://<input type="text"></p> Quote Link to comment https://forums.phpfreaks.com/topic/255917-backspace-keypress-not-supported-in-chrome/#findComment-1311860 Share on other sites More sharing options...
The Little Guy Posted January 28, 2012 Author Share Posted January 28, 2012 I went with the background image idea. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/255917-backspace-keypress-not-supported-in-chrome/#findComment-1311862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.