Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank a field and take out text when user clicks on it

Status
Not open for further replies.

JVKAdmin

IS-IT--Management
Dec 28, 2001
155
CA
Hi everyone,

I'm working on trying to come up with a simple script to take out default text from a field when a user goes to click on it. the defaulted values I want to leave in to direct the user for the proper format of the text they are entering. So far this is what I have which works when I am editing frontpage on my own Windows 2000 Professional IIS 5.0 workstation but when i upload the page to the website, I keep getting a runtime error saying " 'document.Form.Field' is a null or not an object"

heres the code i have so far

<Script>
function Blank1() {
var blanktext = &quot;&quot;
document.NewUser.Phone1.value=blanktext
}
function Blank2() {
var blanktext = &quot;&quot;
document.NewUser.FAX.value=blanktext
}
function Blank3() {
var blanktext = &quot;&quot;
document.NewUser.Street.value=blanktext
}
function Blank4() {
var blanktext = &quot;&quot;
document.newuser.NewUser.City.value=blanktext
}
function Blank5() {
var blanktext = &quot;&quot;
document.NewUser.StateProvince.value=blanktext
}
function Blank6() {
var blanktext = &quot;&quot;
document.NewUser.Email.value=blanktext
}
</Script>

then for each field i have something similar to this

<input type=&quot;text&quot; name=&quot;Street&quot; size=&quot;25&quot; tabindex=&quot;3&quot; value=&quot;Street&quot; Onclick=Blank3()>

i have an example up at
Any help appreciated

Thanks

------------------------------------------------
Kevin Karr
Network Administrator / WebMaster
CNE, MCP, A+
Jack Van Klaveren Ltd.
1894 Seventh St.
St. Catharines ON
Canada
(905) 641-5599 ext. 2328
Sales Service: 1-800-665-1642
Fax: (905) 684-6260
kkarr@jvk.net
 
Somewhere in your script you must be trying to call document.form.field rather than document.NewUser.Street or some other field. I tried your script and it behaves correctly. I would change the onClick to Onfocus in case they are tabbing through the form.

Check the code for document.form.field DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
DeZiner,

Thanks for taking the time to reply. I am fairly new to scripts so bare with me. I am not quite sure what you mean by me calling document.form.field when I already have document.NewUser.Street for example.. One thing I am not clear on is what the first word document refers to in that string. I assume that this is a way in which to call the current html document. Does it require the current name of the document I am working on or is it a preset object?

i know that .newuser.street is the form and the field which i want to reference..

The code for the actuall form was generated by frontpage 2002 so I don't know if theres something with that which is affecting the code but I can't find any line that has document.form.field in there. How did you test the code?



 
The script is looking for a form fied, in the current documnet named Field.

document.<--Current PageForm.<-- This should be the &quot;name&quot; of the form.Field<--Looking for the form field named &quot;Field&quot;

After you load the page in the browser look at the script and see if there is a line in the script that reads document.form.field.

Better yet, post the link and we'll have a look. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Deziner,

Okay well you can look at the source by going to
Its really weird because if I run the page in preview mode the code works but if I publish or view it from Internet explorer it won't work.
 
Here is the problem:

Look above where I broke down what each part of the error meant. document.form.field

Your actual error is (clicking on phone #):
document.NewUser.Phone1 is null or not an object. The object that is missing is &quot;NewUser&quot;. You are telling it in your script to look at the current document, inside the object called NewUser at the part of that object called Phone1. The NewUser object in this case is the form. The form needs to have the name &quot;NewUser&quot;. Right now this line of code exsists:
<form method=&quot;POST&quot; name=&quot;FrontPage_Form1&quot;
action=&quot;_vti_bin/shtml.dll/newuser.html&quot; onsubmit=&quot;return FrontPage_Form1_Validator(this)&quot; language=&quot;JavaScript&quot;
webbot-action=&quot;--WEBBOT-SELF--&quot;>
I gave up FP because of this. You can either not use the webbots for submitting a form and write your own form processing script or change the script you already wrote to read:
document.FrontPage_Form1.FAX.value = blanktext
DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Deziner,

I change the value in my script to Frontpage_Form1. Whats weird is that it appears to default to that Form Name since I have changed it before. Anyways I still can't get it to work correctly. I don't want to write another script for my form since I simply don't know how. If you can think of any other suggestions to try I'd appreciate it. I must be missing something.

 
I just went to the page and it works FANTASTIC!

Check it out on the web or from someone else's PC. Good work my friend. DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Deziner,

I should mention that I scrapped my entire script heheh what i ended up doing was just putting in this command in the field definition itself

OnFocus=value=&quot;&quot;

There is one flaw however which is everytime the focus changes to that field from another again (say the user wants to change something) it re-blanks out the line.

I didn't need to have all the Javascripting .. But I am still curious as to why it wouldn't work before..

I think what they say is still true, always try to find the simpliest solutions. IT makes sense to because theres a lot less code :)

Anyways if your still feeling curious about the previous code let me know if you solve it !

Thanks for all of your Help BTW !



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top