Wrox Home  
Search P2P Archive for: Go

  Return to Index  

javascript thread: Formatting text and the eval function


Message #1 by "Alexander Bienz" <alex@v...> on Mon, 4 Mar 2002 14:29:41
form1 in this case is a collection and myTarget is the name of the element.

All elements in the web page are part of collection of some other element.

for example if you using
	var currentMessage = document.form1.myTarget.value;

myTarget would be in form1 collection.
form1 would be in document collection etc'.

you also can use your own arrays. Like

var arr = new Array()

arr['par1'] = 'something 1';
arr['par2'] = 'something 2';
arr['par3'] = 'something 3';
arr['par4'] = 'something 4';
etc'.


Oleg.
-----Original Message-----
From: Alex Bienz(viplondon) [mailto:alex@v...]
Sent: March 04, 2002 9:35 AM
To: javascript
Subject: [javascript] RE: Formatting text and the eval function


I can't believe it, I've been stuck on this problem for ages and it's as
simple as that!

It works, thanks!

Could you explain to me the background of this, I was told to use eval
because something like, inside a function variables passed into the function
aren't recognised, so that's why my code was such a mess.

Cheers,
	Alex.

-----Original Message-----
From: Oleg Kapeljushnik [mailto:c-oleg.kapeljushnik@w...]
Sent: 04 March, 2002 14:36
To: javascript
Subject: [javascript] RE: Formatting text and the eval function


Why don't you use like this :
	var currentMessage = document.form1[myTarget].value;

Oleg.

-----Original Message-----
From: Alexander Bienz [mailto:alex@v...]
Sent: March 04, 2002 9:30 AM
To: javascript
Subject: [javascript] Formatting text and the eval function


Hi there folks,

I've got a problem with a javascript function that I'm calling for use
when inputting data into a texarea text box.

Basically the function you will see is used to add a URL into a texbox for
the user so they don't have to type in the HTML code themselves, this is
the code so far, there may be one or two mistakes in it...

function DoPrompt(action,myTarget) {
	var revisedMessage;
	var currentMessage = eval('document.form1.'+myTarget+'.value');

	if (action == "url") {
		var thisURL = prompt("Enter the complete URL for the link
you wish to add.", "http://");
		if(thisURL!=null){
			var urlUBBCode = "<a href='"+thisURL+"' class='b'
target='_blank' onFocus='if(this.blur)this.blur()'>"+thisURL+"</a>";
			revisedMessage = currentMessage+urlUBBCode;
			var result = currentMessage=revisedMessage;
			//eval('document.form1.'+myTarget+'.focus();');
			return result;
		}
	}

Now I've been told that evalhas to be asigned to something so I'm not sure
how to use it correctly but what I'm trying to do with this code is make
it dynamic so that the same code can be used for different
texboxes 'myTarget'.  and then return the result to the target textbox.
however the problem I'm getting at the moment, is that on the line that
says...

revisedMessage = currentMessage+urlUBBCode;

an error occurs saying unterminated string constant or something like
that, any ideas how I can eith simplify this or correct it?

Thanks in advance.





  Return to Index