...

View Full Version : Undefined error



woncler
06-17-2010, 04:41 PM
Hi,

I'm not sure did I post this to the right area, but here's my problem...

Let's make this simple, I am totally newbie in coding.

I installed a lightbox patch to FCKeditor, and I tried to modify it a bit so I could add a title into it. I kind of managed but...

Here's the html code which I added to the html file:

<div>
<br />
<input id="txtTitleLightBox" style="width: 100%" type="text" />
</div>

And these are the modified codes which I added to the js file:

var rel = oLink.rel;
if (rel)
{
var type;
if (rel.indexOf("[") > 0)
type = rel.substring(0,rel.indexOf("["));
else
type = rel;
var oE = GetE('rad'+type);
if (oE)
{
GetE('txtTitleLightBox').value= title;
GetE('txtGroupLightBox').value= rel.substring(rel.indexOf("[")+1, rel.indexOf("]"));
GetE('chkLightBox').checked = true;
GetE('rad'+type).checked = true;
}
}

if (GetE('chkLightBox').checked && oLink)
{
var rel = "lightbox"
var rad = document.getElementsByName('radLightBoxType')
for (var i=0; i < rad.length; i++)
{
if (rad[i].checked)
{
rel = rad[i].value;
break;
}
}

oLink.title = title
var title = GetE('txtTitleLightBox').value = title;
oLink.rel = rel
var group = GetE('txtGroupLightBox').value
if (group)
{
oLink.rel += "[" + group + "]"
}
}


And what I added as new code were

oLink.title = title
var title = GetE('txtTitleLightBox').value = title;
and

GetE('txtTitleLightBox').value= title;

The result is (eg) this kind of html text:

<a title="undefined" rel="lightbox" href="image/path"><img width="200" height="113" alt="" src="image/path" /></a>
So the title is undefined even if I fill something to the txtTitleJavaScript box...

If you want to investigate the full files, they are here:

http://jump.fm/IYOXH

.. thanks :s

tomws
06-17-2010, 05:54 PM
Didn't you already post this question?

Here's what I see:

oLink.title = title
var title = GetE('txtTitleLightBox').value = title;

Concerning the title highlighted in red, where is that defined before you use it?

woncler
06-17-2010, 08:57 PM
... nowhere :D

So should I add under

{
rel = rad[i].value;
break;
}


something like

{
title = rad[i].value;
break;
}


I'm so sorry that even I'm a total dummy, I trie to modify something myself... :s

And whoops, yes I did post this question already... Sorry :D

tomws
06-17-2010, 09:16 PM
I doubt it. Does that radio button contain the desired title text? If not, no.

What confuses me is why you're attempting to set the link title (I guess) with this:


oLink.title = title

But then redefine the title variable immediately after it with this:

var title = GetE('txtTitleLightBox').value = title;


Is there some method to this madness or are you just copy/pasting junk around because you don't know what you're doing? If the latter, you might rather want to swap the order of those two lines.

Old Pedant
06-17-2010, 10:08 PM
Ummm...

This line:


var title = GetE('txtTitleLightBox').value = title;

will *NOT* modify the value of the variable named title.

It assigns the *existing* value of title to the form field (or whatever that is) and then *RE-ASSIGNS* it right back into...the variable title.

*Possibly* this would work:


var title = GetE('txtTitleLightBox').value; // *GET* the value from the form field...
oLink.title = title; // must be *AFTER* defining the variable

But who knows?

tomws
06-17-2010, 10:12 PM
Well, that shows how well I pay attention. I didn't even see that assignment dangling off the end. I blame it on the access control list code I've been staring at all week. Yeah, that's it. :(

woncler
06-18-2010, 09:32 AM
I love youu ♥_♥ It's working perfectly now. If you're interested what I did, I added this code

{
title = txt.value;
break;
}
and that code, which Old Pedant sent.

I know that it is very stressful when people like me come and ask completely stupid questions... Thanks for your patience. :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum