Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

Change data in field after submit?

sending a defalt value in html form fields.



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 :)


3:10 pm on Aug 26, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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.


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!


10:43 pm on Aug 26, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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.


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?


2:15 pm on Aug 28, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

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.


1:49 pm on Sep 11, 2012 (gmt 0)

5+ Year Member

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.

Featured Threads

Hot Threads This Week

Hot Threads This Month