homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / HTML
Forum Library, Charter, Moderators: incrediBILL

HTML Forum

Change data in field after submit?
sending a defalt value in html form fields.

Msg#: 4488357 posted 12:47 am on Aug 26, 2012 (gmt 0)

Hi all!

I have a simple problem (I hope).

I wanted the text fields full instead of extra text on the page,
so I'm using the "onfocus" and "onblur" events in a form.
value='Enter Your First Name Here'



The problem is, if they don't enter any information,
the script captures the value data instead.

Here's the complete form:

<form method='POST' action='http://www.MYWEBSITE.com/cgi-bin/arp3/arp3-formcapture.pl'>
<div align='center'><center>
<p>Step 1:<br><input type='text' name='first_name' size='30'value='Enter Your First Name Here'


<input type='hidden' name='capitals' value='1'>
<div align='center'><center>
<p>Step 2:<br><input type='text' name='email' size='30'value='Enter Your Email Here'



<div align='center'><center>
<p>Step 3:<br><input type='text' name='custom_petname' size='30'value='Enter Your Pets Name'



<input type='hidden' name='subscription_type' value=''><div align='center'><center>
<p><input type='image' SRC="images/Green%2001-Get%20It%20Now%20Big.png" style=
"BORDER-BOTTOM: black solid; BORDER-LEFT: black solid; WIDTH: 160px; HEIGHT: 36px; BORDER-TOP: black solid; BORDER-RIGHT: black solid"
<input type='hidden' name='id' value='2'>
<input type='hidden' name='extra_ar' value=''>
<input type='hidden' name='first_name_man' value='1'>

*******************END PASTE********************

The form captures "Enter Your Pets Name" as the pet's name.
I wouldn't mind if the captured data was blank, but this is a problem.

I know I can leave the field blank if they click the field, using "onfocus=null",
but if they don't even click the field, the text doesn't clear.

Ultimately, if they don't enter anything,
I would like to send "your pet" to the string.

Any help would be great, this is just a bit beyond me.
And thanks for your time everyone!
You got a great place here :)



WebmasterWorld Senior Member 10+ Year Member

Msg#: 4488357 posted 3:10 pm on Aug 26, 2012 (gmt 0)

Since you should accommodate users running with JavaScript disabled, your 'formcapture.pl' script should be modified to filter out these default values. I'd probably add some hidden fields to the <form> to pass the default values to the script so that you don't have to update the script every time you update the <form>. The script will know to look for and ignore those values. So you could have hidden fields like:

<input type="hidden" name="default-email" value="Enter Your Email Here">

Program the script to scan the submitted field names for "default-", extract the corresponding field name/value pairs and process the form data accordingly.


Msg#: 4488357 posted 8:18 pm on Aug 26, 2012 (gmt 0)

I wish I could edit the formcapture.pl,
but it is part of a script I bought, and it's encrypted :(

Thanks for the thoughts though!


WebmasterWorld Senior Member 10+ Year Member

Msg#: 4488357 posted 10:43 pm on Aug 26, 2012 (gmt 0)

If you can't edit the script, I'd suggest that you pre-populate the form fields with your defaults using JavaScript instead of using the 'value' attribute in the <input> tags. That way, users running without JavaScript won't have those fields filled with invalid data. And then you'll want to add an 'onsubmit' function to strip out the default values before sending the data on to the script.


Msg#: 4488357 posted 9:52 pm on Aug 27, 2012 (gmt 0)

I thought about using JavaScript,
I was actually looking at this:

But my thought is, if the user has it disabled,
wouldn't that leave blank fields on the form,
with no explanation about what they were?


WebmasterWorld Senior Member 10+ Year Member

Msg#: 4488357 posted 2:15 pm on Aug 28, 2012 (gmt 0)

When you added onblur() and onfocus(), you were already using JavaScript, so you should provide some plain text labels for those running without JavaScript - perhaps in a <noscript> section so your original design is left intact for most users.


Msg#: 4488357 posted 1:49 pm on Sep 11, 2012 (gmt 0)

newer browsers also use the placeholder attribute in input fields
<input type="text" placeholder="Enter Your First Name Here" value="">

This will act just like the javascript you're using now.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / HTML
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved