#1 (permalink)  
Old 10-04-2008, 11:10 AM
Registered User
 
Join Date: Oct 2008
Posts: 6
Email Contact Forms?

Hello,

I am trying to develop an email contact form being that the text disappears when someone click on the field and reappears (if nothing is inputted) in that field and that "your name", "email", "phone number", and "comments" being required fields and "company name", and "fax" not required.

here is the code:

HTML pastebin - collaborative debugging tool

Can someone please help me get this form working that it would use our email servers?
Reply With Quote

  #2 (permalink)  
Old 10-04-2008, 09:29 PM
curtiss's Avatar
Moderator
 
Join Date: May 2003
Posts: 1,438
You're going to need javascript (or Flash, but I'd prefer Javascript, as it's much lighter weight) to do this.

To do so, you'd need an array of the form element ids and an array of the values you want in the form elements when they're blank.

Then, you need to build a function that's going to be invoked when the focus is on the form element and another function that will be invoked when the focus leaves that element.

Here are some examples of the functions (this code should be placed inside the "head" area of your page):
Code:
<script type="text/javascript" language="javascript">
var idarray = Array('yourname','email','phone'); // Add all of the ids of the form elements that you want to fill
var valarray = Array('Your name','Your email address','Your phone number'); // Add the values you want to insert, in exactly the same order you entered the ids above

function fillField(what) {
	var fEl = document.getElementById(what);
	for(var i=0;i<idarray.length;i++) {
		if(what == idarray[i]) {
			if(fEl.value.length == 0 || fEl.value == null || typeof(fEl) == 'undefined') {
				fEl.value = valarray[i];
			}
		}
	}
}

function emptyField(what) {
	var fEl = document.getElementById(what);
	for(var i=0;i<idarray.length;i++) {
		if(what == idarray[i]) {
			if(fEl.value == valarray[i]) {
				fEl.value = '';
			}
		}
	}
}
</script>
You then need to add onfocus and onblur event handlers to each form element. That would look something like:
Code:
<input type="text" name="yourname" id="yourname" onblur="fillField(this.id)" onfocus="emptyField(this.id)" />
Finally, you need to add a trigger after your form to fill all the fields with the appropriate values when the page loads:
Code:
<script type="text/javascript" language="javascript">
for(var i=0;i<idarray.length;i++) {
	fillField(idarray[i]);
}
</script>
I posted the code of a complete working page at http://pastebin.com/m7095f9b1
__________________
I hate Internet Explorer! Anyone with me?

Last edited by curtiss; 10-04-2008 at 09:34 PM.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I set a new window size in an email link? Smiling Ogre Programming and Scripting 3 05-02-2007 07:09 PM
Email information window? ehbowen Programming and Scripting 2 03-17-2007 08:38 AM
HTML Email Contact Form Help 211R Programming and Scripting 11 11-25-2006 06:05 PM
sendmail and Exchange Email Accounts curtiss Servers 3 04-30-2006 11:19 AM


All times are GMT -5. The time now is 03:29 AM.

 
Bitrix
Clicky Web Analytics
CloudContacts
Maxtango


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter