开发者

html form value before and value after

I wondered if this was possible: It looks like this:

<tr>
  <td>
   Full Name:
  </td>
  <td>
   <input type='text' class="inputbox" name='fullname' value='<?php echo $fullname; ?>'>
  </td>
</tr>

But I wanted to get rid of the <td>Full Name</td> and instead of that in the input box itself: value="Full Name". But the function value='<?php echo $fullname; ?> would echo the typed in full name of the person if he did not enter all fields.

My form is made in that way; if someone fills in the form, but leaves one field out, it will echo "please fill in all fields" under the form. But it would be annoying if he had to enter all the information over again! That's where value="<?php echo $fullname; ?> comes in. It will echo the information the user had typed.

So I need a value that shows "Full Name" normally but after a user put in his full name:"John Smith" but not all fields, he would get the "enter all fields" and the "Full Name" Would change in "John Smith".

At this moment he will get "John Smith" if he did not enter all fields, but i wan't the field too show "Full Name" before the user entered "John Smith" And NOT show "Full Name" again.

So in other words I need two values, one that shows normally, and after submit is presses it will echo $fullname.

I hope you guys understand what I 开发者_如何学JAVAmean.

Greetz


I think what you are looking for are placeholders...

 <input type='text' class="inputbox" name='fullname' placeholder="Your name..." />

Please note placeholders are not supported by older browsers.


Maybe you like the placeholder? If the input-field has no value, it will show the placeholder, else it will show the value. Another option is working with an if-condition:

<input name="textfield" type="text" value="<?php echo (isset($_POST["textField"]) ? $_POST["textField"] : "Full name")?> />


<input type='text' class="inputbox" name='fullname' value='<?php echo isset($fullname) ? $fullname : 'Full Name:' ?>'>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜