Jump to content

setting default value for a from text box


jjmusicpro

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.