Chrisj Posted October 28, 2013 Share Posted October 28, 2013 I have this Form code that works successfully to Search a web site (below). How can I add text in the field/box that will disappear when the field/box is selected to add search keywords to? Also, how can I widen the field/box? Any help/examples/suggestions will be appreciated. <form method="get" action="search.php"> <div id="siteSearch"> Enter Search Words <img src="themes/default/images/arrow-red.png"> <input type="hidden" name="type" value="videos"/> <input type="text" name="keyword" id="sbi1" value="" onfocus="if(this.value==this.defaultValue) this.value='';"> <input type="image" align="middle" src="images/search.png" name="sa" value="Search" id="mySearch"/><br/> </div> </form> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/ Share on other sites More sharing options...
Barand Posted October 28, 2013 Share Posted October 28, 2013 Are you talking about a 'placeholder' <input type="text" name="keyword" id="sbi1" size="20" placeholder="Enter keywords" /> Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1455941 Share on other sites More sharing options...
Chrisj Posted October 29, 2013 Author Share Posted October 29, 2013 Thanks for your reply, however I tried this and it didn't affect the Form at all: <input type="text" name="keyword" id="sbi1" size="20" placeholder="Enter keywords" value="" onfocus="if(this.value==this.defaultValue) this.value='';"> Any additional help will be appreciated Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456009 Share on other sites More sharing options...
cyberRobot Posted October 29, 2013 Share Posted October 29, 2013 Which browser are you using to view the form? Note that the placeholder attribute doesn't work in older browsers like IE9. More information can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456013 Share on other sites More sharing options...
Chrisj Posted October 29, 2013 Author Share Posted October 29, 2013 Thank you for your reply. Well, I'm looking for another solution then, if the placeholder doesn't work on all browsers. Any additional help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456029 Share on other sites More sharing options...
cyberRobot Posted October 29, 2013 Share Posted October 29, 2013 It looks like you already have the JavaScript in place. It could be modified as follows: <input type="text" name="keyword" id="sbi1" value="default value" onfocus="if(this.value=='default value') this.value='';"> You would just need to change both instances of "default value" to whatever you need the default value to be. To answer your other question, the input field can be widened with the "size" attribute. More information about the <input> tag and its attributes can be found here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456054 Share on other sites More sharing options...
Chrisj Posted October 31, 2013 Author Share Posted October 31, 2013 Thanks for that reply and link. Much appreciated. Can you please tell me how I can change the font color of the text that replaces: "default value" ? Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456385 Share on other sites More sharing options...
cyberRobot Posted October 31, 2013 Share Posted October 31, 2013 You can use CSS to change the color: https://www.google.com/search?q=html+input+value+color Of course, that will change the color of any text entered in the input filed. If you only want the placeholder text to be a certain color, you can change it dynamically with JavaScript: https://www.google.com/search?q=javascript+text+color+style Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456386 Share on other sites More sharing options...
Chrisj Posted October 31, 2013 Author Share Posted October 31, 2013 Thanks, but with all due respect, I could research this on line via google, but I am hoping to get some specific code help here, on this forum, regarding changing the color of the placeholder text only for this specific line code. Thanks again for any specific help. Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456391 Share on other sites More sharing options...
cyberRobot Posted October 31, 2013 Share Posted October 31, 2013 The Google links provide examples on how to accomplish what you're asking. If you try it out and it doesn't work, feel free to post again with the updated code. Otherwise, perhaps someone else is willing to write the code for you. I honestly don't have the time. You could also consider posting something in the Freelancing forum. http://forums.phpfreaks.com/forum/20-php-freelancing/ Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456393 Share on other sites More sharing options...
.josh Posted October 31, 2013 Share Posted October 31, 2013 Thanks, but with all due respect, I could research this on line via google, but I am hoping someone can just write my code for me (for free) so I don't have to make an effort at doing my own work. Thanks again for any specific help. fixed. Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456396 Share on other sites More sharing options...
boompa Posted November 1, 2013 Share Posted November 1, 2013 fixed. And its corollary, "I learn better by example so please provide revised code." Quote Link to comment https://forums.phpfreaks.com/topic/283388-help-adding-field-box-text-to-search-form/#findComment-1456478 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.