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

  • Steve[D]
  • Newbie
  • Newbie
  • Steve[D]
  • Posts: 6

Post 3+ Months Ago

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
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

If you're already pulling and populating an email address into the input, why do you want to replace it with 'Enter your Emai..."?
  • Steve[D]
  • Newbie
  • Newbie
  • Steve[D]
  • Posts: 6

Post 3+ Months Ago

Its ok, I thought of a workaround - used a background image saying enter email address :)
  • UPSGuy
  • Lurker ಠ_ಠ
  • Web Master
  • User avatar
  • Posts: 2733
  • Loc: Nashville, TN

Post 3+ Months Ago

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".
  • IcyDragoon
  • Student
  • Student
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

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
  • IcyDragoon
  • Posts: 65

Post 3+ Months Ago

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 109 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
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.