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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alternative for using ID tag in Netscape? 3

Status
Not open for further replies.

JBijleveld

Programmer
Apr 5, 2001
8
0
0
NL
Hi to all,

I have a challange in making a page (for both IE and Netscape,both version >= 4). That page should contain an inputbox, and some extra information (metadata) about the inputbox, which I have to use in JavaScript for checking the information on the client and displaying a correct infomative message to the user.

I tried things like:
<INPUT NAME=&quot;T1&quot; MSG=&quot;This is textbox 1&quot; ID=&quot;FirstTextbox&quot; VALUE=&quot;123&quot;>

The problem is that I cannot access extra information in a tag in Javascript in Netscape (IE has no troubles displaying the extra attributes like MSG).

I wondered if it is possible to add extra info with things like a <SPAN> or <DIV> tag in such a way that I can access it both in Netscape and IE. I actually need only one extra value for now, but in future I might require more than one.

Any help would be greatly appreciated!

Best regards, J.Bijleveld
 
i dont think netscape 4.x and lower support extra attributes in tags.... you might want to try the element.getAttribute() method, but, i doubt that will work. luciddream@subdimension.com
 
Thanks for the reply, I just tried and it didn't work indeed. I wonder if there's another way to accomplish the same, like using layers/DIV/SPAN tags.

For example:
<SPAN ID=&quot;FirstTextbox&quot;><INPUT NAME=&quot;T1&quot; VALUE=&quot;123&quot;></SPAN>

Do you know if it's possible to get the ID of the SPAN tag that embraces the input control? I just cannot figure out what syntax to use to do so in NS.

IE has no problem reading those values...

If there's no other solution, I can now manage to put the information in a separate javascript procedure and do a lookup on the name of the control, but I definitely prefer a more robust solution!

Thanks for your time.
 
I assume you'll do some sort of processing on the contents of the input box, so why not pass your metadata within the onClick event, for example:

<input name=&quot;t1&quot; value=&quot;123&quot; onClick=&quot;myFunction('this is the meta data', 't1');&quot;>

I don't know if this will work for what you have in mind but it passes the input object and the string metadata into the function for you to parse/process.

Let me know if it helps!

Tiz --
Tim <tim@planetedge.co.uk>
 
my solution would be to scrap NS4.x and lower... but, as far as i know, you cannot get the id of an element in NS4. and, i don't think NS4 supports enough of the dom to get the parentNode of an element, even if you could get the ID. luciddream@subdimension.com
 
i'm afraid you'll have to build an alternate web page for ns and such, putting all your extra info in hidden fields ... it's the only workaround i can think of ... :-(
 
or you could use an associative array.... luciddream@subdimension.com
 

Thanks for all suggestions!

Tiz: I'm afraid your solution won't work in my case since I want to use the value of the ID for creating a piece of XML to send back the content of a form. I need the ID to insert extra information for composing the XML. Thanks anyway!

Luciddream: It's a pitty but I cannot just ignore NS :(
since my endusers insist on using it.

Iza: That's indeed a possibility, although I hoped to find another way to work around it.

Luciddream: Using an associative array sounds promising to me, although I don't exactly know what it is and how to use it. Can you perhaps point me at some example of it?

 
Umm here's a complete stab in the dark and quick mockup of what I meant - it only works in Netscape at the moment but it should work in IE too once you add some browser checking.

I don't follow what you're trying to do exactly with the ID tag and XML. This example passes the name of the input box then looks it up in an array for the associated meta data. Then you can do what you want with it.

I think I'm probably still off-track but let me know more details.

Code:
<SCRIPT>

function metaStruct( id, msg ) {
	this.id = id;
	this.msg = msg;
}


var metadata = new Array;
metadata[0] = new metaStruct('T1', 'This is text box one');
metadata[1] = new metaStruct('T2', 'This is text box two');

function getMetaInf ( idx ) {
	for(i=0;i<metadata.length;i++) {
		if(metadata[i].id == idx) {
			return metadata[i].msg;
		}
	}

	return 'No meta data';
}

function processButtons ( ) {

	for(i=0;i<document.test.elements.length;i++)
	{
		theName = document.test.elements[i].name;
		if(theName.indexOf('T') == 0) {

			theMeta = getMetaInf(theName);
			alert('Name: ' + theName + '\nMeta Inf: ' + theMeta);
		}
	}

}

</SCRIPT>

<form name=&quot;test&quot;>
<input type=&quot;text&quot; name=&quot;T1&quot;>
<input type=&quot;text&quot; name=&quot;T2&quot;>
<input type=&quot;text&quot; name=&quot;T3&quot;>

<input type=&quot;button&quot; onClick=&quot;javascript:processButtons();&quot;>
</form>
--
Tim <tim@planetedge.co.uk>
 
var arr = new Array();
arr['T1'] = 'text';

so, now you can use the name of the field to get the additional info out of the array.
luciddream@subdimension.com
 
both hidden fields and associative array requires you to duplicate information : in the tag for ie AND in the fields/array for ns ( - the hidden fields/array solution is cross browser tho)
i hope it's a dynamically generated page !!!!
 

luciddream: OK, I see it's fairly simple to work around the ID tag, which is both flexible and extensible.

iza: Yes, indeed it's a dynamically generated page. I think I stick to the array solution since cross-browser portability is an issue in this project. Using Hidden fields isn't really useable in my situation, though.
 
good luck :) (veel geluk ;-) !!!!)
and come back here if you have some troubles with your arrays !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top