Newbie Question: How to define value in form when using PHP?

  • Steve[D]
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 07, 2008
  • Posts: 6
  • Status: Offline

Post August 26th, 2009, 6:22 am

Hi,

Im creating a form for vistors to enter their email address in to sign up to our newsletter.

Before the user clicks on the input box I want it to say "Enter Your Email Address Here". Then when they click on it the text disappears.

This seems pretty straight forward normally by using the value="......." and onfocus="......." commands, but my value definition is already set as value="<?php get_data("email"); ?>".

So what can I do? Ive tried using onblur to set it, but that only works once the user clicks on and off the input box. Is there a way to initiate onblur when the page first loads?

Heres the full form code:

Code: [ Select ]
<form action="mail5.php" method="post"><p>

<label><input type="text" name="email" id="email" class="input" value="<?php get_data("email"); ?>" onfocus="this.value=''" onblur="this.value='Enter Email Address'"/></label>

<input type="submit" name="submit" id="submit" value="SEND" class="inputbutton"/>
</p></form>
  1. <form action="mail5.php" method="post"><p>
  2. <label><input type="text" name="email" id="email" class="input" value="<?php get_data("email"); ?>" onfocus="this.value=''" onblur="this.value='Enter Email Address'"/></label>
  3. <input type="submit" name="submit" id="submit" value="SEND" class="inputbutton"/>
  4. </p></form>



Many Thanks,
Steve. :)
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post August 26th, 2009, 6:22 am

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post August 26th, 2009, 7:40 am

If you're already pulling and populating an email address into the input, why do you want to replace it with 'Enter your Emai..."?
I'd love to change the world, but they won't give me the source code.
  • Steve[D]
  • Newbie
  • Newbie
  • No Avatar
  • Joined: Oct 07, 2008
  • Posts: 6
  • Status: Offline

Post August 26th, 2009, 7:46 am

Its ok, I thought of a workaround - used a background image saying enter email address :)
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Joined: Jul 25, 2005
  • Posts: 2735
  • Loc: Nashville, TN
  • Status: Offline

Post August 26th, 2009, 9:35 am

heh, ok, but I still don't get why you would rather do that than test if the value you've pulled via php is blank or not, and if not, then change input value to "please enter".
I'd love to change the world, but they won't give me the source code.
  • IcyDragoon
  • Student
  • Student
  • No Avatar
  • Joined: Mar 12, 2008
  • Posts: 65
  • Status: Offline

Post August 26th, 2009, 9:05 pm

I think thats what you want:

Code: [ Select ]
<input type="text" value="Click Here" onfocus="if(this.value=='Click Here')this.value=''" onblur="if(this.value=='')this.value='Click Here'" />


.....nvm, you already have a value for the text input. you can try to do a floating div or just div
  • IcyDragoon
  • Student
  • Student
  • No Avatar
  • Joined: Mar 12, 2008
  • Posts: 65
  • Status: Offline

Post August 26th, 2009, 9:07 pm

UPSGuy wrote:
heh, ok, but I still don't get why you would rather do that than test if the value you've pulled via php is blank or not, and if not, then change input value to "please enter".


client site checking optimizes user experience*

though you still want to do the server site checking

Post Information

  • Total Posts in this topic: 6 posts
  • Users browsing this forum: No registered users and 209 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.