MyBB Community Forums

Full Version: How to add text into a form box?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to know how you get the text in the form box before you've even clicked it, heres my current coding:

<form action="member.php" method="post">
<input type="text" class="textbox" name="username" size="16" maxlength="{$mybb->settings['maxnamelength']}"/>
<input type="password" class="textbox" name="password" size="16"/>
<td><input type="submit" class="button" name="submit" value="{$lang->login}" /></td>
<input type="hidden" name="action" value="do_login" />
<input type="hidden" name="url" value="{$redirect_url}" />
</form>
What do you mean? You want to actually "get" the values in a field? Or pre-populate it?
I guess pre populate it, I want it to say "Username" in the user box and "Password" in the pass box.
Ok, then you can 1)Just Set it on the value attribute or 2)Set it on the value, and remove it when the user clicks the input (focus actually), and re-add it if the field was left blank.

To make 1) Simply add an attribute to your input like
value="Your value"

To make 2) Set the value you want (as in 1)). Now Add a onfocus event like this:
onfocus="if(this.value == 'Your value') { this.value = ''; }"
so when the user clicks the field to write something, the default text will be gone. Now, to reset the default value if the filed is left blank when the user abandon the input (blur), add an onblur even:
 onblur="if(this.value=='') { this.value='Your value'; }"
Thanks I got it now Big Grin