|
-
Apr 17th, 2003, 04:23 AM
#1
Thread Starter
Frenzied Member
Accessing form elements for Netscape 4.7
I have some JavaScript that accesses an element in a form:
window.document.forms[formID].elements[elementID].value
Where formID contains the name of the form and elemntID contains the name of the element. This works fine with IE and newer versions of Netscape.
How can I change this so it will work with Netscape 4.7? - I don't mind if I need to do a check for browser version and use a different code for the different browsers.
Any help appreciated.
-
Apr 18th, 2003, 02:49 AM
#2
Make sure all form elements have both the the id and name properties set.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 22nd, 2003, 03:01 AM
#3
Thread Starter
Frenzied Member
Yes they are the same. But I'm not sure I have explained well enough...
function resetFormField(formID,elementID,defaultText) {
if (document.forms[formID].elements[elementID].value == defaultText) {
document.forms[formID].elements[elementID].value = '';
}
}
This javascript function is called by an onFocus event:
<input type="text" name="textfield" id="textfield" value="Enter keywords here" onFocus="resetFormField('FreeTextSearch','textfield','Enter keywords here');">
Works fine in IE and newer version of Netscape.
Any ideas?
-
Apr 22nd, 2003, 03:42 AM
#4
Yeah. Ignore NS 4 It's a terrible browser anyway.
Is the function even called in NS4? Maybe it doesn't know the onFocus event. Use an onClick instead.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 22nd, 2003, 03:49 AM
#5
Thread Starter
Frenzied Member
I can't ignore NS4 (true it is a truely terrible browser) but unfortunately people still use it!
I'll check if NS4 recognises the onFocus event. Can't use onClick for this particular instance.
Thanks.
-
Apr 22nd, 2003, 03:53 AM
#6
Thread Starter
Frenzied Member
Just checked up and onFocus is available for IE4+ and NS3+ so that can't be it.
I've got a feeling the problem is caused by the form and element name being created dynamically in the javascript code.
-
Apr 22nd, 2003, 09:41 AM
#7
Very likely, yes. Have you tried with predefined ones?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Apr 22nd, 2003, 09:42 AM
#8
Note also that NS on Mac never recognizes names that contain an underscore.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|