jjmusicpro Posted March 28, 2008 Share Posted March 28, 2008 setting default value for a from text box so i created a form with username firstname lastname and description. I wanted the description field to be filled with a default value of "worker", but if they type over that, i wanted it to enter that value into db. i just didnt know if the value="worker" will almost make the desciprtion box worker. Quote Link to comment Share on other sites More sharing options...
Cep Posted March 28, 2008 Share Posted March 28, 2008 If your setting a default value for a specific set of data (one the user cannot customise) you really want to use a drop down menu instead. If your users can customise the data in the field then you would only need to check for a blank or null value and then use an if statement like this, <?php if ($_POST['myvalue']==="") { $myvalue = "worker"; } ?> Of course you would have first validated the post variable before reaching this point. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 for a textarea (I'm assuming for a description field) there should not be a value attribute. <textarea>Default value here</textarea> Quote Link to comment Share on other sites More sharing options...
jjmusicpro Posted March 28, 2008 Author Share Posted March 28, 2008 yeah not text areas, these will be text box's. by default i want the text box to say "worker" but also give them an option to type in whatever over that.. but i dont want it to pass the default text "worker" if its been typed over. I think if i used "value=worker" for a text box, regardless of what they put in, it will always be worker. Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 28, 2008 Share Posted March 28, 2008 Incorrect. Value will be ignored if the user typed in something different. This is really on the browser side of things though... so if it's not working for you, try using a standardized browser like FireFox, Opera, or even IE7. Quote Link to comment Share on other sites More sharing options...
Cep Posted March 28, 2008 Share Posted March 28, 2008 Ah no, as discomatt says if another value is written into the textbox the default will be ignored so you can safely use the attribute value="worker" for a default value. Quote Link to comment 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.