[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Cannot get form field to clear when clicked

Posted on 2007-11-29
9
Medium Priority
?
256 Views
Last Modified: 2009-12-06
I have a phplist subscribe form in the top right of this site:

http://www.mokitaproductions.org/index.php?page=home

I'm trying to make the text "enter your email" disappear when the form field is clicked. This should be relatively straightforward, but I can't get it to work.

The javascript I'm using is at:

http://www.mokitaproductions.org/list/clearformfield.js

The form code is attached below.

<form method="post" action="http://www.mokitaproductions.org/list/?p=subscribe" name="signup" target="windowName" onsubmit="window.open('', this.target,
	'dialog,modal,scrollbars=no,resizable=no,width=500,height=250,left=0,top=0');">
	<table border="0">
		<tbody>
			<tr>
				<td class="email-box">
				<div align="center">
				<input name="email" id="email" value="enter your email" size="20" onfocus="clearField(this)" type="text" />
				<script language="Javascript" type="text/javascript">
				addFieldToCheck("email","Email");</script>
				</div>
				</td>
				<td class="attributeinput"> </td>
				<td class="submit"><input class="formInputButton" name="subscribe" value="join mailing list" onclick="return checkform();" type="submit" /></td>
			</tr>
			<input name="htmlemail" value="1" type="hidden" />
		</tbody>
	</table>
	<input name="list[2]" value="signup" type="hidden" /><input name="listname[2]" value="Mokita" type="hidden" />
	<div style="display: none">
	<input name="VerificationCodeX" size="20" type="text" />
	</div>
</form>

Open in new window

0
Comment
Question by:gajones76
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
9 Comments
 
LVL 16

Expert Comment

by:grahamnonweiler
ID: 20377974
You can achieve the same reuslt without any additional scripts as shown the attached snippet correspnding to your above line 8.


<input name="email" id="email" value="enter your email" size="20" onfocus="if(this.value=='enter your email') {this.value=''}" type="text" />

Open in new window

0
 

Author Comment

by:gajones76
ID: 20378037
thanks Graham. I have put your code into the form on this page only:

http://www.mokitaproductions.org/index.php?page=home

but, for some reason it is still not working....


0
 
LVL 16

Expert Comment

by:grahamnonweiler
ID: 20378112
You have part of the script missing...

should be:

onFocus="if(this.value=='enter your email')  { this.value='' }"

where the '' after the = in value are two single quotes.



0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20378146
The reason that the function that you used didn't work, is that you didn't specify the defaultValue argument that it uses:

<input name="email" id="email" value="enter your email" defaultValue="enter your email" size="20" onfocus="clearField(this)" type="text" />


Regardning the code that you are using now:

change

<input name="email" id="email" value="enter your email" size="20" onfocus="if(this.value=='enter your email') " type="text" />

to

<input name="email" id="email" value="enter your email" size="20" onfocus="if(this.value=='enter your email') { this.value=''; }" type="text" />
0
 

Author Comment

by:gajones76
ID: 20378382
thanks. however it still doesn't work:

http://www.mokitaproductions.org/index.php?page=form-test

the first time I load that page, the following error is displayed:

string(131) "Smarty error: [in globalcontent:mailinglist line 8]: syntax error: unrecognized tag: this.value='' (Smarty_Compiler.class.php, line 446)" string(119) "Smarty error: [in globalcontent:mailinglist  line 8]: syntax error: unrecognized tag '' (Smarty_Compiler.class.php, line 590)"

Subsequent reloads of the page remove the error, but also strip out the offfending code from the form:

{ this.value=''; }"

I'm using cmsmadesimple and wonder whether that has something to do with it. Whether i put the code directly into the page or in a content block the result is the same.
0
 
LVL 29

Expert Comment

by:Göran Andersson
ID: 20378628
The system that you are using uses brackets, which is unfortunate, as Javascript does too.

Fortunately, you don't need the brackets in this Javascript:

<input name="email" id="email" value="enter your email" size="20" onfocus="if(this.value=='enter your email') this.value='';" type="text" />
0
 

Author Comment

by:gajones76
ID: 20378674
thanks for that. In the end I found there is a {literal} tag in the CMS that you can wrap around to preserve the code.
0
 

Accepted Solution

by:
ee_auto earned 0 total points
ID: 25982783
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question