exhaler Posted March 12, 2009 Share Posted March 12, 2009 hi, i was wondering how i can change the font color after a user has typed in something in an input field i did this $(document).ready(function() { $("#firstbranch").click(function(){ $('#free').animate({ fontSize: "24px" }); }); <td style="width: 98px" valign="top" align="left"> <font color="#B9A49B" face="Arial" style="font-size: 8pt"> first branch location </font> </td> <td valign="middle" align="left" style="width: 210px"> <input type="text" name="firstbranch" size="35" style="font-size: 8pt; font-family: Arial; color: #56443D; background-color:#DCD6C7"> </td> <td valign="middle" align="left"> <font color="#B9A49B" face="Arial" style="font-size: 8pt"> <b>(for free)</b> </font> </td> but nothing happend, i just want to change the color or font of "for free" when the user enters something in the input field thx Quote Link to comment https://forums.phpfreaks.com/topic/149188-change-font-color-when-there-is-text-in-input-field/ Share on other sites More sharing options...
Adam Posted March 13, 2009 Share Posted March 13, 2009 Place this JavaScript within the <head> of your HTML.. <script type="text/javascript"> function updateText(obj) { if (obj.value != '') { document.getElementById('updateText').style.color = '#00FF00'; } else { document.getElementById('updateText').style.color = '__normal color here__'; } return; } </script> And part of your code with the changes made.. <td valign="middle" align="left" style="width: 210px"> <input type="text" name="firstbranch" size="35" style="font-size: 8pt; font-family: Arial; color: #56443D; background-color:#DCD6C7" onkeyup="updateText(this);"> </td> <td valign="middle" align="left"> <span id="updateText"><b>(for free)</b></span> </td> It's a very basic function but you can build on it if or when you need to. EDIT: Added "else" condition.. Adam Quote Link to comment https://forums.phpfreaks.com/topic/149188-change-font-color-when-there-is-text-in-input-field/#findComment-783758 Share on other sites More sharing options...
exhaler Posted March 13, 2009 Author Share Posted March 13, 2009 thanks MrAdam, but i was hoping to do one in jquery Quote Link to comment https://forums.phpfreaks.com/topic/149188-change-font-color-when-there-is-text-in-input-field/#findComment-783896 Share on other sites More sharing options...
darkfreaks Posted March 13, 2009 Share Posted March 13, 2009 Jquery Autocomplete: http://docs.jquery.com/Plugins/Autocomplete Quote Link to comment https://forums.phpfreaks.com/topic/149188-change-font-color-when-there-is-text-in-input-field/#findComment-783924 Share on other sites More sharing options...
exhaler Posted March 13, 2009 Author Share Posted March 13, 2009 the autocomplete is very handy but that's not what i want, i'll stick with the code MrAdam gave, thx again Quote Link to comment https://forums.phpfreaks.com/topic/149188-change-font-color-when-there-is-text-in-input-field/#findComment-783948 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.