1 Replies - 425 Views - Last Post: 17 April 2008 - 05:12 AM

#1 avinash1109  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-April 08

character output from an array

Post icon  Posted 15 April 2008 - 01:17 PM

hello, i've been with this code for quite some time. I'm using an input text box to get a string from the user. Then using javascript, i'm looking for the location of the character in an array and then replace in by another character in a different array but at the same position.

The problem is that when i'm sending the output to a textbox,I'm getting an "undefined " message followed by the correct output. Can anyone help me how to get rid of the "undefined" message that is sent to the output text box.

Thanks in advance.
The javascript code is below:

function encrypt(){
var te= new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');  
var encrypt=new Array('W','X','Y','Z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','w','x','y','z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v');

var str=document.getElementById("input").value;
var l=str.length;
var i,j;
var en,strde;

for(i=0;i<l;i++)
{ 
	for(j=0;j<54;j++)
		{
			if( te[j] == (str.charAt(i)) )
			{
			en = en + encrypt[j];
			}
		document.getElementById("output").value=en;
}
}
}






Is This A Good Question/Topic? 0
  • +

Replies To: character output from an array

#2 deepamanohar  Icon User is offline

  • New D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-March 08

Re: character output from an array

Posted 17 April 2008 - 05:12 AM

hi just place empty string after the declaration of the variable "en"

 en="";



after this statement place your for loop.

the "undefined problem is solved" :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1