Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-09-2006, 02:40 PM   PM User | #1
ak_jsohi4u
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ak_jsohi4u is an unknown quantity at this point
Question Urgent - problem with browsers while parsing innerHTML

Hii,

I am trying to parse the innerHTML like this...

//InnerHTML = "<INPUT id=TreeViewPR1_TreeView1n14CheckBox title=Hostage type=checkbox CHECKED name=TreeViewPR1_TreeView1n14CheckBox>
//<SPAN class=\"TreeViewPR1_TreeView1_0 TreeViewPR1_TreeView1_1\" id=TreeViewPR1_TreeView1t14 title='Extract This string'>Hostage</SPAN>"

function AddNodeid(InnerHTML)
{

var TitleIndex=InnerHTML.lastIndexOf("title=");

if (TitleIndex > 0)
{
var SubString= InnerHTML.substring(TitleIndex+6, InnerHTML.length+1);


var EndIndex=SubString.indexOf("id="); // For Firefox

if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE

var Nodeid=SubString.substring(0, EndIndex);

alert(Nodeid);
}
else
alert("No NodeId");
}


the problems are becoz of browsers..

Firefox interchanges the positions of title and id in <SPAN> tag...

and another prob with this code is that IE returns id without quotes( i.e 01) but FF returnsin double quotes(i.e "01").

can you tell why this happens and is there a way by which I can directly get
title, value pair.

Thanks in advance..

Cheerio
Abhishek
ak_jsohi4u is offline   Reply With Quote
Old 05-09-2006, 03:13 PM   PM User | #2
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
innerHTML is not a standard DOM method, thus it can not insert the new elements into the DOM page's tree. use DOM methods to append new elements.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 05-09-2006, 03:24 PM   PM User | #3
ak_jsohi4u
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ak_jsohi4u is an unknown quantity at this point
Quote:
Originally Posted by Kor
innerHTML is not a standard DOM method, thus it can not insert the new elements into the DOM page's tree. use DOM methods to append new elements.
Hi Kor,

Thanks for replying,
Actually I am not trying to insert anything , ijust want to parse this string(innerHTML) and retrieve the value of 'title' of <SPAN> tag(i.e "Extract this Text"), this funct is working but there are some prob with firefox...

Hope I am more clear now...

Cheerio
Abhishek
ak_jsohi4u is offline   Reply With Quote
Old 05-09-2006, 05:18 PM   PM User | #4
jscheuer1
Regular Coder

 
Join Date: Mar 2005
Location: SE PA USA
Posts: 373
Thanks: 0
Thanked 0 Times in 0 Posts
jscheuer1 is an unknown quantity at this point
Code:
alert(document.getElementById('TreeViewPR1_TreeView1t14').title)
__________________
- John
jscheuer1 is offline   Reply With Quote
Old 05-10-2006, 05:06 AM   PM User | #5
jscheuer1
Regular Coder

 
Join Date: Mar 2005
Location: SE PA USA
Posts: 373
Thanks: 0
Thanked 0 Times in 0 Posts
jscheuer1 is an unknown quantity at this point
BTW, I should add that I saw no discrepancy when I tried out your example, which needed a bit of editing to do anything so, may have lost something in the translation (both IE and FF used the same branch:

Code:
if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE
and returned the same result). Also, InnerHTML is simply a variable, while innerHTML is an object of HTML elements. Finally, I should have included with my above post, a question like, "Why can't you just query the title attribute directly as illustrated?"
__________________
- John
jscheuer1 is offline   Reply With Quote
Old 05-10-2006, 05:09 AM   PM User | #6
ak_jsohi4u
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ak_jsohi4u is an unknown quantity at this point
Quote:
Originally Posted by jscheuer1
Code:
alert(document.getElementById('TreeViewPR1_TreeView1t14').title)
Hii john,

Thanks for the idea, its great, I came to do all this in one line after little modification...

Cheerio
Abhishek
ak_jsohi4u is offline   Reply With Quote
Old 05-10-2006, 06:13 AM   PM User | #7
ak_jsohi4u
New to the CF scene

 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
ak_jsohi4u is an unknown quantity at this point
Quote:
Originally Posted by jscheuer1
BTW, I should add that I saw no discrepancy when I tried out your example, which needed a bit of editing to do anything so, may have lost something in the translation (both IE and FF used the same branch:

Code:
if(EndIndex <=0)
EndIndex=SubString.indexOf(">"); // For IE
and returned the same result). Also, InnerHTML is simply a variable, while innerHTML is an object of HTML elements. Finally, I should have included with my above post, a question like, "Why can't you just query the title attribute directly as illustrated?"
Hi John,

Sorry for not telling this before, actually i am accessing innerHTML like this
for a treeview control of asp.net..

AddNodeid(event.srcElement.parentNode.innerHTML);

FF and IE return different results(just interchange the position of title and id i.e. <SPAN ... title='Extract This string' , id=TreeViewPR1_TreeView1t14 >Hostage</SPAN>"),

But we can access title directly by-

event.srcElement.nextSibling.title

come to know this after your reply

Can you tell any link about differences in tag's supported by IE and FF...

Thanks for your help...

Cheerio
Abhishek
ak_jsohi4u is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:42 AM.


Advertisement
Log in to turn off these ads.