homepage Welcome to WebmasterWorld Guest from 50.17.21.7
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
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.
BradleyD




msg:4488359
 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.
ie:
value='Enter Your First Name Here'

onfocus="this.value=''"

onblur="if(this.value=='')this.value=this.defaultValue;"

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

Here's the complete form:
*******************PASTE********************

<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'

onfocus="this.value=''"

onblur="if(this.value=='')this.value=this.defaultValue;"></p>
</center></div>
<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'

onfocus="this.value=''"

onblur="if(this.value=='')this.value=this.defaultValue;"></p>
</center></div>

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

onfocus="this.value=''"

onblur="if(this.value=='')this.value=this.defaultValue;"></p>
</center></div>

<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"
border="0"
align="center"></p>
</center></div>
<input type='hidden' name='id' value='2'>
<input type='hidden' name='extra_ar' value=''>
<input type='hidden' name='first_name_man' value='1'>
</form>

*******************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 :)
Brad.

 

rainborick




msg:4488447
 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.

BradleyD




msg:4488480
 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!
Brad.

rainborick




msg:4488512
 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.

BradleyD




msg:4488847
 9:52 pm on Aug 27, 2012 (gmt 0)

I thought about using JavaScript,
I was actually looking at this:
[digitalbush.com...]

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?

rainborick




msg:4489095
 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.

lostdreamer




msg:4493776
 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