Click to See Complete Forum and Search --> : HTML question


jllydgnt
07-28-2003, 10:09 AM
Does anyone know a Netscape alternative to this? Works fine in IE.

<input type='text' name='toll_area_code' alt='Toll Free Area Code'>

When I try to use the alt attribute in JavaScript, it is undefined. I have also tried the id and title attributes. Basically, I need a label for an input field that I can show a user.

goldbug
07-28-2003, 10:43 AM
IE's use of the alt="" attribute for tooltips is actually incorrect. The title="" attribute is meant for things like tooltips, the alt="" attribute is intended for things like non-graphical browsers and browsing tools for those who cannot see, for example (short description, not tooltip).

The fact that IE even renders anything for alt="" on an input element is silly. It's definitely not XHTML-compliant, and looks alarmingly proprietary.

Look here for "real" attributes, and other browser-specific notes:

http://blooberry.com/indexdot/html/tagpages/i/inputtext.htm

EDIT: actually, i looked at the XHTML 1.0 DTDs and it does seem to be in there, I stand corrected.


<!ELEMENT input EMPTY> <!-- form control -->
<!ATTLIST input
%attrs;
%focus;
type %InputType; "text"
name CDATA #IMPLIED
value CDATA #IMPLIED
checked (checked) #IMPLIED
disabled (disabled) #IMPLIED
readonly (readonly) #IMPLIED
size CDATA #IMPLIED
maxlength %Number; #IMPLIED
src %URI; #IMPLIED
alt CDATA #IMPLIED
usemap %URI; #IMPLIED
onselect %Script; #IMPLIED
onchange %Script; #IMPLIED
accept %ContentTypes; #IMPLIED
>


Also, XHTML1.1:
http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_extformsmodule

So yeah, I gues it is valid. My bad.

jllydgnt
07-28-2003, 10:54 AM
Do you have any suggestions that will solve my problem with Netscape? Another approach or anything so that I can have a nice, neat label for a user to see. Other than using the name attribute.

goldbug
07-28-2003, 10:54 AM
To actually, make an attempt to answer your question, instead of saying not to do something :) :

Have you tried giving the form field an id="" attribute then calling it by ID?

for example:


<input id="tollfree" type="text" name="toll_area_code" alt="Toll Free Area Code" />

Called with:

<script type="text/javascript">
<!--
var fld = document.getElementById('tollfree');
alert(fld.alt);
// etc... and so on.. call fld.[attribute]

// -->
</script>


document.getElementById should work in any "modern" browser (read: IE 5+, Moz/Netscape (Gecko), Opera 6+)

jllydgnt
07-28-2003, 11:06 AM
I can't get Netscape 4.73 to even recognize the id. Everytime I try to use it(with JavaScript), it is undefined. But, IE is fine with it.

goldbug
07-28-2003, 11:11 AM
Ahh, Netscape 4.x!!

I ignore that crap anymore. Anyone still using it is so outdated, they don't deserve to be looking at any of my pages anyway. :)

You *could* put in a little browser-sniffing code before that that excludes netscape 4 -, ie4 - (or anything else that does javascript but NOT a decent implementation of DOM)

jllydgnt
07-28-2003, 11:15 AM
Using JavaScript, I want to be able to reference a form input by name and access another attribute that will hold some text.


<form name='form'>
<input type='text' name='toll_area_code' id='Some Text'>
</form>


alert(document.form.toll_area_code.id);

I have also tried alt and title. Works in IE, does not work in Netscape.

jllydgnt
07-28-2003, 11:17 AM
As outdated as it may be, my organization still uses it because of some conflicts with higher versions and some software we use. So, I am stuck with 4.73.

goldbug
07-28-2003, 11:18 AM
Don't mean to keep bothing, but can I ask why ?? The reason I am asking, is that whatever methods you pull off in Javascript, are very very easily defeated as soon as one turns off Javascript support. (Easy as one click in Firebird w/ WebDev extension)

goldbug
07-28-2003, 11:21 AM
Originally posted by jllydgnt
alert(document.form.toll_area_code.id);

That kind of JavaScript doesn't always work in Netscape.

If you *must* use Netscape 4.crap, maybe something along the lines of:

var nam = document.forms['formname'].elements['elementname'].name;

, for example. I'm not sure, however, that Netscape 4 can handle elements and attributes it didn't outright support (can't read any old attribute). If it didn't support the alt="" attribute (probably not), then you can't reference it, plain and simple.

jllydgnt
07-28-2003, 11:25 AM
No security concerns. If they have JavaScript disabled, they will see a message telling them not to submit this form. If they ignore it and still submit, the only one hurt will be them. They will submit without some of the required info and it will be ignored. I mean, I not using JavaScript to prevent them from dropping my DB or anything.

goldbug
07-28-2003, 11:26 AM
Looking at my handy-dandy chart (just unearthed it from pile of papers)....

The only thing listed under a text input field, as far as supported properties (In IE3, Netscape 2->4.x), is:

defaultValue
form
name
type
value
blur()
focus()
handleEvent()
select()
onBlur
onChange
onFocus
onKeyDown
onKeyPress
onKeyUp
onSelect

Sorry, but I don't see alt in there, probably not possible in ye olde Netscape.

jllydgnt
07-28-2003, 11:27 AM
Originally posted by goldbug


var nam = document.forms['formname'].elements['elementname'].name;



Dude, I need an attribute other than "name" that I put some text into to show the user.

goldbug
07-28-2003, 11:31 AM
Alright, alright. Clearly this isn't going to work embedding something in a tag somewhere. If you're using Javascript, why not just put whatever text into an associative array, keys named after the form field.

You have:

<input name="foo" type="text" value="bar" />


In javascript somewhere:

var words = new Array();
words['foo'] = 'This is the field for BAR!';

jllydgnt
07-28-2003, 11:34 AM
Cause it's about 140 fields or so. I'm lookin' for the easy way out. Don't think I'm gonna find it. You do have a good idea there. Looks like I might end up using it. Thanks for your help.

goldbug
07-28-2003, 11:42 AM
Perhaps there's a way you can tie in that array with some event firing. For example, after the user is done filling out that field and goes to the next, it can populate your array (and still be somewhat "inline/embedded").

Ex:

<input type="text" name="foo" onblur="fldThingy(this,'The field you enter bar into!');" />

Handled by:

<script type="text/javascript">
<!--
var txtArray = new Array();
function fldThingy (fld,fldtxt)
{
txtArray[fld.name] = fldtxt;
}

// -->
</script>