473,396 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

writing information to a div

304 100+
hi,
I have written a small script that will display data in a div tag ...the data to be displayed will change every two seconds.

The problem that i am having with this script is that,
in internet explorer i get an error "expected )" [This error does not occur every time i run the script.say once in every 5 runs it appears. Try refreshing the page again and again].

in firefox, nothing gets displayed...i am stumped on that!!


The code :

var names;
var i = 0;
function displaynames(name)
{
names = name.split("###");
heading.style.visibility="visible";
heading.style.display = "block";
heading.innerText = names[i];
i=i+1;
var t = setTimeout('shownames()',2000);
}
function shownames()
{
if (i<names.length)
{
heading.innerText = names[i];
i=i+1;
var t = setTimeout('shownames()',2000);
}
else
{
i=0;
heading.innerText = names[i];
i=i+1;
var t = setTimeout('shownames()',2000);
}


The input to displaynames is in this format -> "wow###yipee"

any help would be appreciated...

thanks,
gomzi.
Apr 14 '07 #1
16 1837
gomzi
304 100+
hey guys...i think i have got a pretty good idea of whats going wrong here...

I have some strings like this-> windows xp 'microsoft' in the database..

so when am trying to display them, i get an error saying expected ')'

i.e. it wrongly considers the single quote as the end of the string...

is there anyway how i can overcome this?
Apr 14 '07 #2
hi pal
first u are missin a }
at the very end!!!

and instead of using
i=i+1;
use
i++;
i can help u with it ,when i understand the way u want it.!
so do u have an textbox for entering names seperated by ###
and u want to write them in a div every 2 sec
Or
do u have an array of names?
and u want to write them in a div every 2 sec

im curious
peace
Apr 14 '07 #3
gomzi
304 100+
hi pal
first u are missin a }
at the very end!!!

and instead of using
i=i+1;
use
i++;
i can help u with it ,when i understand the way u want it.!
so do u have an textbox for entering names seperated by ###
and u want to write them in a div every 2 sec
Or
do u have an array of names?
and u want to write them in a div every 2 sec

im curious
peace

thanks mate....
ya. i have the } at the end..forgot to copy it here.

i have an array of names. These names have been put into the array by separating them .... i.e. say tom###jerry has been put into two positions in an array , one containing tom and the other jerry.
Apr 14 '07 #4
hi pal
eh could you post a bit of this array
im having trouble understanding it
is it like

names = new Array();
names[0]='tom';
names[1]='jerry';

or

names = new Array();
names[0]='tom###jerry';

which would be very weird
ps firefox does not support innerText use innerHTML instead
hahaha
well peace to u
Apr 14 '07 #5
gomzi
304 100+
hi pal
eh could you post a bit of this array
im having trouble understanding it
is it like

names = new Array();
names[0]='tom';
names[1]='jerry';

or

names = new Array();
names[0]='tom###jerry';

which would be very weird
ps firefox does not support innerText use innerHTML instead
hahaha
well peace to u

yup..its of the first type.tried innerHTML. firefox didnt display that either!!
Apr 14 '07 #6
so if im correct
u have an arra like this:

names = new Array();
names[0]='tom';
names[1]='jerry';

and u want to write it into a div or span like this

tom###jerry

every 2 sec?
Apr 14 '07 #7
gomzi
304 100+
so if im correct
u have an arra like this:

names = new Array();
names[0]='tom';
names[1]='jerry';

and u want to write it into a div or span like this

tom###jerry

every 2 sec?

nope....its something like this...

initially i have this - > tom###jerry in a variable say var1 (string)

then,

i separate it into tom & jerry and put it into a variable named names which is an array...
something like what you guessed..
names = new Array();
names[0]='tom';
names[1]='jerry';

now, i want to display these two items alternatively every 2 seconds.

but the problem is that in case the string is something like say...

tom###je'rry'

then when i pass this string to the displaynames function,
i get an error that the expected ')' aint there.
Apr 14 '07 #8
gomzi
304 100+
And one more thing....
The string can contain single quotes as i just showed...

or

double quotes, like -> tom###je"rry"

or

any other character for that matter...

so, is there a way of encoding the strings so that it wont create a problem in any case?
Apr 14 '07 #9
hmmm thats a difficult

are the strings predefined or is it userinput?

take a look at this
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 10-4-2007 -->
  3. <head>
  4.   <title>JavaScript : Generate A Array Tool</title>    
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta name="description" content="JavaScript : Generate A Array Tool">
  7. <meta name="keywords" content="JavaScript : Generate A Array Tool">
  8. <meta name="author" content="FJH de Hoog"> 
  9. <script language="JavaScript1.2"> 
  10. //Author : fjhdehoog
  11. //use this code on 1 condition, leave the author comment intact ,thank you 
  12. //leave empty 
  13. var Thisarrayname='';
  14. var mystring ='';
  15. var Seperator='<br>';
  16. count=0;
  17.  
  18. function startwait(){
  19. state=document.getElementById('Progressspan')
  20. state.style.backgroundColor='red';
  21. state.innerHTML='Please Wait';
  22. setTimeout('GetInput()',500);
  23. function waitFinished(){ 
  24. state=document.getElementById('Progressspan')
  25. state.style.backgroundColor='green'; 
  26. state.innerHTML='Ready';
  27. function GetInput(){
  28. Thisarrayname=generatearrayform.ArrayNameTB.value;
  29. mystring = generatearrayform.ArrayElements.value;
  30. //Check for input Thisarrayname.indexOf(' ')
  31. if (Thisarrayname.indexOf(' ')==-1){}else{alert('No spaces allowed for Array Name.!!!');waitFinished();return false;}
  32. if (Thisarrayname==''){alert('Field Array Name Is Empty!!!');waitFinished();return false;}else{}
  33. if (mystring==''){alert('Field Array Elements Is Empty!!!');waitFinished();return false;}else{}
  34. //trim left
  35. while (mystring.substring(0,1) == ' '){
  36. mystring = mystring.substring(1, mystring.length);} 
  37. //trim right
  38. while (mystring.substring(mystring.length-1, mystring.length) == ' '){
  39. mystring = mystring.substring(0,mystring.length-1);}
  40. //check first char ,if contains a number return false
  41. isvalid=Thisarrayname.substring(0,1);
  42. for (i=0;i<10;++i){
  43. if (isvalid!=i){}else{alert('Invalid Array Name.\nCannot start with a number');waitFinished();return false;}
  44. }          
  45. //
  46. TheArrayGenerated.innerHTML='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+'</tt></b></font><font color="#008000"> = </font>new <font color="#ff0000">Array</font><font color="#008000">();</font><br>';
  47. //reset count
  48. count=0; 
  49. //call GenerateArray()
  50. GenerateArray();
  51.  
  52.  }
  53. function GenerateArray(){ 
  54. //if the string is emmpty do nothing
  55. if (mystring=='' || mystring==' '){/*alert ('mystring is empty');*/}
  56. else { 
  57. //get the first space
  58. getspace=mystring.indexOf(' ')+1;
  59. //if there is no space left , we assume it is the last word
  60. if (getspace==0){
  61. //get the remaining string length
  62. xxx=mystring.length; 
  63. //read the string from first char to its last
  64.  
  65. firstword=mystring.substring(0,xxx);
  66. //****Trim left and right******** 
  67. while (firstword.substring(0,1) == ' '){firstword = firstword.substring(1, firstword.length);}
  68. while (firstword.substring(firstword.length-1, firstword.length) == ' '){firstword= firstword.substring(0,firstword.length-1);}
  69. /***********/
  70. //read from position xxx to it remaining length *** seems useless but its needed
  71. newstring=mystring.substring(xxx,mystring.length);
  72. //write the firstword to span
  73. TheArrayGenerated.innerHTML+='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+"</tt></b></font><font color='#008000'>[</font><font color='#ff00ff'>"+count+"</font><font color='#008000'>]</font>='"+firstword+"'<font color='#008000'>;</font>";
  74. count++; 
  75. //make sure mystring is empty
  76. mystring='';
  77. waitFinished();
  78. }else{    
  79. //if there is a space left ,read the string from the first char to the first space
  80. firstword=mystring.substring(0,getspace); 
  81. //then write it to span
  82. //****Trim left and right******** 
  83. while (firstword.substring(0,1) == ' '){firstword = firstword.substring(1, firstword.length);}
  84. while (firstword.substring(firstword.length-1, firstword.length) == ' '){firstword= firstword.substring(0,firstword.length-1);}
  85. /***********/
  86. TheArrayGenerated.innerHTML+='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+"</tt></b></font><font color='#008000'>[</font><font color='#ff00ff'>"+count+"</font><font color='#008000'>]</font>='"+firstword+"'<font color='#008000'>;</font>"+Seperator;
  87. count++;
  88. //read the string from the first space to the end and assign it to newstring
  89. newstring=mystring.substring(getspace,mystring.length);
  90. //set the remaining string as mystring
  91. mystring=newstring;    
  92. //call GenerateArray() again bcuzz there are still words left
  93. GenerateArray();
  94. }
  95. }
  96. function Clearfields() {
  97. generatearrayform.ArrayNameTB.value='';
  98. generatearrayform.ArrayElements.value='';
  99. }
  100. </script>
  101. <style>
  102. .Btn{width:100%;}
  103. .Progressview{width:100%;background-color:green;text-align:center;font-weight:bold;} 
  104. .ArrayElementsInput{width:100%;font-family:georgia;color:blue;}
  105. .ArrayNameTBInput{width:100%;font-family:tahoma;color:red;}
  106. </style>
  107. </head>
  108. <body>
  109.  
  110. <table border=1 bgcolor="dodgerblue" bordercolor=#000000 summary="" align="center">
  111. <form name="generatearrayform">
  112. <tr>
  113. <td colspan="3"><div style="text-align: center"><font color="#ffffff" size="3"><em><tt><b>JavaScript Generate A Array Tool By fjhdehoog</b></tt></em></font></div></td>
  114. </tr>
  115. <tr>
  116. <td colspan="3"><font color="#ffffff"><tt>Enter the Array Name:</tt></font><br>
  117. <input type="text" class="ArraynameTBInput" name="ArrayNameTB" maxlength="256" value="Example"><br>
  118. <font color="#ffffff"><tt>Enter the Array elements seperated by a single space:</tt></font><br>
  119. <textarea class="ArrayElementsInput" name="ArrayElements" rows="10">AliceBlue AntiqueWhite Aqua Aquamarine Azure Beige Bisque Black BlanchedAlmond Blue BlueViolet Brown BurlyWood CadetBlue Chartreuse Chocolate Coral CornflowerBlue Cornsilk Crimson Cyan DarkBlue DarkCyan DarkGoldenRod DarkGray DarkGreen DarkKhaki DarkMagenta DarkOliveGreen Darkorange DarkOrchid DarkRed DarkSalmon DarkSeaGreen DarkSlateBlue DarkSlateGray DarkTurquoise DarkViolet DeepPink DeepSkyBlue DimGray DodgerBlue FireBrick FloralWhite ForestGreen Fuchsia Gainsboro GhostWhite Gold GoldenRod Gray Green GreenYellow HoneyDew HotPink IndianRed Indigo Ivory Khaki Lavender LavenderBlush LawnGreen LemonChiffon LightBlue LightCoral LightCyan LightGoldenRodYellow LightGrey LightGreen LightPink LightSalmon LightSeaGreen LightSkyBlue LightSlateGray LightSteelBlue LightYellow Lime LimeGreen Linen Magenta Maroon MediumAquaMarine MediumBlue MediumOrchid MediumPurple MediumSeaGreen MediumSlateBlue MediumSpringGreen MediumTurquoise MediumVioletRed MidnightBlue MintCream MistyRose Moccasin NavajoWhite Navy OldLace Olive OliveDrab Orange OrangeRed Orchid PaleGoldenRod PaleGreen PaleTurquoise PaleVioletRed PapayaWhip PeachPuff Peru Pink Plum PowderBlue Purple Red RosyBrown RoyalBlue SaddleBrown Salmon SandyBrown SeaGreen SeaShell Sienna Silver SkyBlue SlateBlue SlateGray Snow SpringGreen SteelBlue Tan Teal Thistle Tomato Turquoise Violet Wheat White WhiteSmoke Yellow YellowGreen</textarea><br></td>
  120. </tr>
  121. <tr>
  122. <td width="33%"><input class="Btn" type="button" value="Generate Array" onclick="startwait()"></td>
  123. <td width="33%"><input class="Btn" type="button" onclick="Clearfields()" value="Clear"></td>
  124. <td width="33%"><span id="Progressspan" class="Progressview">Ready</span></td>
  125. </tr>
  126. <tr>
  127. <td colspan="3" bgcolor="white"><span id="TheArrayGenerated" ></span></td>
  128. </tr>
  129. </form>
  130. </table>
  131. </body>
  132. </html>
  133.  
and this

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 14-4-2007 -->
  3. <head>
  4.   <title></title>
  5. <script language="JavaScript1.2"> 
  6. var i = 0;
  7. function displaynames(){
  8. heading=document.getElementById('mydiv');
  9. names=document.getElementById('nameinput').value;
  10. nextname = names.split("###");
  11.  
  12. if (nextname[i]==null){
  13. heading.innerHTML = 'finished';
  14. return false;
  15. }else{
  16. heading.innerHTML = nextname[i];
  17.  
  18. i++;
  19. setTimeout('displaynames()',2000);
  20. }
  21. }
  22.  
  23. </script> 
  24. </head>
  25. <body onload="displaynames()">
  26. <form>
  27. <input type="text" id="nameinput" size="40" value="111##222###333###444###555"maxlength="256">
  28.  
  29. </form>
  30. <div id="mydiv"></div>
  31. </body>
  32. </html>
  33.  
i hope u gain some insight from it
because im a bit lost
i know what u mean but i cant get the point that there would be/get qoutes
in the string?
and why the ###?
instead of a single space?
peace m8
Apr 14 '07 #10
acoder
16,027 Expert Mod 8TB
Escape the strings in your server-side script using backslash, i.e. replace all single quotes with:
Expand|Select|Wrap|Line Numbers
  1. \'
Apr 16 '07 #11
gomzi
304 100+
hmmm thats a difficult

are the strings predefined or is it userinput?

take a look at this
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 10-4-2007 -->
  3. <head>
  4.   <title>JavaScript : Generate A Array Tool</title>    
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <meta name="description" content="JavaScript : Generate A Array Tool">
  7. <meta name="keywords" content="JavaScript : Generate A Array Tool">
  8. <meta name="author" content="FJH de Hoog"> 
  9. <script language="JavaScript1.2"> 
  10. //Author : fjhdehoog
  11. //use this code on 1 condition, leave the author comment intact ,thank you 
  12. //leave empty 
  13. var Thisarrayname='';
  14. var mystring ='';
  15. var Seperator='<br>';
  16. count=0;
  17.  
  18. function startwait(){
  19. state=document.getElementById('Progressspan')
  20. state.style.backgroundColor='red';
  21. state.innerHTML='Please Wait';
  22. setTimeout('GetInput()',500);
  23. function waitFinished(){ 
  24. state=document.getElementById('Progressspan')
  25. state.style.backgroundColor='green'; 
  26. state.innerHTML='Ready';
  27. function GetInput(){
  28. Thisarrayname=generatearrayform.ArrayNameTB.value;
  29. mystring = generatearrayform.ArrayElements.value;
  30. //Check for input Thisarrayname.indexOf(' ')
  31. if (Thisarrayname.indexOf(' ')==-1){}else{alert('No spaces allowed for Array Name.!!!');waitFinished();return false;}
  32. if (Thisarrayname==''){alert('Field Array Name Is Empty!!!');waitFinished();return false;}else{}
  33. if (mystring==''){alert('Field Array Elements Is Empty!!!');waitFinished();return false;}else{}
  34. //trim left
  35. while (mystring.substring(0,1) == ' '){
  36. mystring = mystring.substring(1, mystring.length);} 
  37. //trim right
  38. while (mystring.substring(mystring.length-1, mystring.length) == ' '){
  39. mystring = mystring.substring(0,mystring.length-1);}
  40. //check first char ,if contains a number return false
  41. isvalid=Thisarrayname.substring(0,1);
  42. for (i=0;i<10;++i){
  43. if (isvalid!=i){}else{alert('Invalid Array Name.\nCannot start with a number');waitFinished();return false;}
  44. }          
  45. //
  46. TheArrayGenerated.innerHTML='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+'</tt></b></font><font color="#008000"> = </font>new <font color="#ff0000">Array</font><font color="#008000">();</font><br>';
  47. //reset count
  48. count=0; 
  49. //call GenerateArray()
  50. GenerateArray();
  51.  
  52.  }
  53. function GenerateArray(){ 
  54. //if the string is emmpty do nothing
  55. if (mystring=='' || mystring==' '){/*alert ('mystring is empty');*/}
  56. else { 
  57. //get the first space
  58. getspace=mystring.indexOf(' ')+1;
  59. //if there is no space left , we assume it is the last word
  60. if (getspace==0){
  61. //get the remaining string length
  62. xxx=mystring.length; 
  63. //read the string from first char to its last
  64.  
  65. firstword=mystring.substring(0,xxx);
  66. //****Trim left and right******** 
  67. while (firstword.substring(0,1) == ' '){firstword = firstword.substring(1, firstword.length);}
  68. while (firstword.substring(firstword.length-1, firstword.length) == ' '){firstword= firstword.substring(0,firstword.length-1);}
  69. /***********/
  70. //read from position xxx to it remaining length *** seems useless but its needed
  71. newstring=mystring.substring(xxx,mystring.length);
  72. //write the firstword to span
  73. TheArrayGenerated.innerHTML+='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+"</tt></b></font><font color='#008000'>[</font><font color='#ff00ff'>"+count+"</font><font color='#008000'>]</font>='"+firstword+"'<font color='#008000'>;</font>";
  74. count++; 
  75. //make sure mystring is empty
  76. mystring='';
  77. waitFinished();
  78. }else{    
  79. //if there is a space left ,read the string from the first char to the first space
  80. firstword=mystring.substring(0,getspace); 
  81. //then write it to span
  82. //****Trim left and right******** 
  83. while (firstword.substring(0,1) == ' '){firstword = firstword.substring(1, firstword.length);}
  84. while (firstword.substring(firstword.length-1, firstword.length) == ' '){firstword= firstword.substring(0,firstword.length-1);}
  85. /***********/
  86. TheArrayGenerated.innerHTML+='<font face="Fixedsys" color="#000000"><b><tt>'+Thisarrayname+"</tt></b></font><font color='#008000'>[</font><font color='#ff00ff'>"+count+"</font><font color='#008000'>]</font>='"+firstword+"'<font color='#008000'>;</font>"+Seperator;
  87. count++;
  88. //read the string from the first space to the end and assign it to newstring
  89. newstring=mystring.substring(getspace,mystring.length);
  90. //set the remaining string as mystring
  91. mystring=newstring;    
  92. //call GenerateArray() again bcuzz there are still words left
  93. GenerateArray();
  94. }
  95. }
  96. function Clearfields() {
  97. generatearrayform.ArrayNameTB.value='';
  98. generatearrayform.ArrayElements.value='';
  99. }
  100. </script>
  101. <style>
  102. .Btn{width:100%;}
  103. .Progressview{width:100%;background-color:green;text-align:center;font-weight:bold;} 
  104. .ArrayElementsInput{width:100%;font-family:georgia;color:blue;}
  105. .ArrayNameTBInput{width:100%;font-family:tahoma;color:red;}
  106. </style>
  107. </head>
  108. <body>
  109.  
  110. <table border=1 bgcolor="dodgerblue" bordercolor=#000000 summary="" align="center">
  111. <form name="generatearrayform">
  112. <tr>
  113. <td colspan="3"><div style="text-align: center"><font color="#ffffff" size="3"><em><tt><b>JavaScript Generate A Array Tool By fjhdehoog</b></tt></em></font></div></td>
  114. </tr>
  115. <tr>
  116. <td colspan="3"><font color="#ffffff"><tt>Enter the Array Name:</tt></font><br>
  117. <input type="text" class="ArraynameTBInput" name="ArrayNameTB" maxlength="256" value="Example"><br>
  118. <font color="#ffffff"><tt>Enter the Array elements seperated by a single space:</tt></font><br>
  119. <textarea class="ArrayElementsInput" name="ArrayElements" rows="10">AliceBlue AntiqueWhite Aqua Aquamarine Azure Beige Bisque Black BlanchedAlmond Blue BlueViolet Brown BurlyWood CadetBlue Chartreuse Chocolate Coral CornflowerBlue Cornsilk Crimson Cyan DarkBlue DarkCyan DarkGoldenRod DarkGray DarkGreen DarkKhaki DarkMagenta DarkOliveGreen Darkorange DarkOrchid DarkRed DarkSalmon DarkSeaGreen DarkSlateBlue DarkSlateGray DarkTurquoise DarkViolet DeepPink DeepSkyBlue DimGray DodgerBlue FireBrick FloralWhite ForestGreen Fuchsia Gainsboro GhostWhite Gold GoldenRod Gray Green GreenYellow HoneyDew HotPink IndianRed Indigo Ivory Khaki Lavender LavenderBlush LawnGreen LemonChiffon LightBlue LightCoral LightCyan LightGoldenRodYellow LightGrey LightGreen LightPink LightSalmon LightSeaGreen LightSkyBlue LightSlateGray LightSteelBlue LightYellow Lime LimeGreen Linen Magenta Maroon MediumAquaMarine MediumBlue MediumOrchid MediumPurple MediumSeaGreen MediumSlateBlue MediumSpringGreen MediumTurquoise MediumVioletRed MidnightBlue MintCream MistyRose Moccasin NavajoWhite Navy OldLace Olive OliveDrab Orange OrangeRed Orchid PaleGoldenRod PaleGreen PaleTurquoise PaleVioletRed PapayaWhip PeachPuff Peru Pink Plum PowderBlue Purple Red RosyBrown RoyalBlue SaddleBrown Salmon SandyBrown SeaGreen SeaShell Sienna Silver SkyBlue SlateBlue SlateGray Snow SpringGreen SteelBlue Tan Teal Thistle Tomato Turquoise Violet Wheat White WhiteSmoke Yellow YellowGreen</textarea><br></td>
  120. </tr>
  121. <tr>
  122. <td width="33%"><input class="Btn" type="button" value="Generate Array" onclick="startwait()"></td>
  123. <td width="33%"><input class="Btn" type="button" onclick="Clearfields()" value="Clear"></td>
  124. <td width="33%"><span id="Progressspan" class="Progressview">Ready</span></td>
  125. </tr>
  126. <tr>
  127. <td colspan="3" bgcolor="white"><span id="TheArrayGenerated" ></span></td>
  128. </tr>
  129. </form>
  130. </table>
  131. </body>
  132. </html>
  133.  
and this

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 14-4-2007 -->
  3. <head>
  4.   <title></title>
  5. <script language="JavaScript1.2"> 
  6. var i = 0;
  7. function displaynames(){
  8. heading=document.getElementById('mydiv');
  9. names=document.getElementById('nameinput').value;
  10. nextname = names.split("###");
  11.  
  12. if (nextname[i]==null){
  13. heading.innerHTML = 'finished';
  14. return false;
  15. }else{
  16. heading.innerHTML = nextname[i];
  17.  
  18. i++;
  19. setTimeout('displaynames()',2000);
  20. }
  21. }
  22.  
  23. </script> 
  24. </head>
  25. <body onload="displaynames()">
  26. <form>
  27. <input type="text" id="nameinput" size="40" value="111##222###333###444###555"maxlength="256">
  28.  
  29. </form>
  30. <div id="mydiv"></div>
  31. </body>
  32. </html>
  33.  
i hope u gain some insight from it
because im a bit lost
i know what u mean but i cant get the point that there would be/get qoutes
in the string?
and why the ###?
instead of a single space?
peace m8
thanks man for posting the code so that i could understand as to how the thing works...

As far as the strings are concerned they are not predefined, they come from the database and can be anything.

m separating the strings by ### because i am sure that no string will contain three hashes together and hence can be a sure way of separating them in javascript.
Apr 16 '07 #12
gomzi
304 100+
Escape the strings in your server-side script using backslash, i.e. replace all single quotes with:
Expand|Select|Wrap|Line Numbers
  1. \'
thanks acoder...

ya.m doing that as of now...but its just a temporary solution ........

i will start receiving errors if the string contains any other special character....

so is there any encoding technique that i can use?
Apr 16 '07 #13
acoder
16,027 Expert Mod 8TB
You can perhaps use the escape function, but what other special characters cause errors?
Apr 16 '07 #14
gomzi
304 100+
You can perhaps use the escape function, but what other special characters cause errors?
Even if a string contains a double quote i get this error.

i cannot use escape function because, the string that i am passing to the javascript function is through asp.net. I tried using server.htmlencode available in .net, but it wasn't much helpful.
Apr 16 '07 #15
hi pal
im back again,
and i think im on to something!

check this. :)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 14-4-2007 -->
  3. <head>
  4.   <title></title>
  5. <script language="JavaScript1.2">  
  6. //array of non allowed characters
  7. NotAllowed = new Array();
  8. NotAllowed[0]='@';
  9. NotAllowed[1]='!';
  10. NotAllowed[2]='"';
  11. NotAllowed[3]='$';
  12. NotAllowed[4]='%';
  13. NotAllowed[5]='&';
  14. NotAllowed[6]='_';
  15. NotAllowed[7]='(';
  16. NotAllowed[8]=')';
  17. NotAllowed[9]='\'';
  18. NotAllowed[10]='?';
  19. NotAllowed[11]='/';
  20. NotAllowed[12]='\\';
  21. NotAllowed[13]='~';
  22. NotAllowed[14]='°';
  23. NotAllowed[15]='¸';
  24. NotAllowed[16]='}';
  25. NotAllowed[17]='{';
  26. NotAllowed[18]='£';
  27. NotAllowed[19]='¾';
  28. NotAllowed[20]='½';
  29. NotAllowed[21]='¼';
  30. NotAllowed[22]='¬';
  31. NotAllowed[23]='§';
  32. NotAllowed[24]='|';
  33. NotAllowed[25]='¨';
  34. NotAllowed[26]='*';
  35. NotAllowed[27]='<';
  36. NotAllowed[28]='>';
  37. NotAllowed[29]='`';
  38. NotAllowed[30]='´';
  39. NotAllowed[31]='±';
  40. NotAllowed[32]='=';
  41. NotAllowed[33]='-';
  42. NotAllowed[34]='.';
  43. NotAllowed[35]=';';
  44. NotAllowed[36]=':';
  45. NotAllowed[37]=',';
  46. NotAllowed[38]='.';
  47. NotAllowed[39]='»';
  48. NotAllowed[40]='µ';
  49. NotAllowed[41]='¦';
  50. NotAllowed[42]='[';
  51. NotAllowed[43]=']';
  52. NotAllowed[44]='#';
  53. NotAllowed[45]=' ';        
  54.  
  55. var i = 0;
  56. function displaynames(){
  57. heading=document.getElementById('mydiv');//the display div
  58. names='111###22"2###3#33###44"4###55$5###6%66###7&77###8_88###9(99###101 010';//the string
  59.  
  60. nextname = names.split("###");//split names
  61.  
  62. for (XxX=0;XxX<NotAllowed.length;++XxX){
  63. teststring=nextname[i].indexOf(NotAllowed[XxX])+1;//compare string for illegal charaters by looping through array 
  64. if(teststring!='0'){//if an illegal charater has been found 
  65. firstpart=nextname[i].substring(0,teststring-1);//get the first piece of string before illegal character
  66. secondpart=nextname[i].substring(teststring,nextname[i].length);//get the last piece of the string behind the illegal character
  67. nextname[i]=firstpart+secondpart;//rejoin them
  68. else{
  69.  
  70. }
  71. }
  72.  
  73. if (nextname[i]==null){
  74. heading.innerHTML = 'finished';
  75. return false;
  76. }else{
  77. heading.innerHTML = nextname[i];
  78. i++;
  79. setTimeout('displaynames()',2000);
  80. }
  81. }
  82.  
  83.  </script> 
  84. </head>
  85. <body onload="displaynames()">
  86.  
  87. <div id="mydiv"></div>
  88. </body>
  89. </html>
  90.  
  91.  
well let me know what u think
peace
Apr 16 '07 #16
gomzi
304 100+
hi pal
im back again,
and i think im on to something!

check this. :)

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <!-- Created on: 14-4-2007 -->
  3. <head>
  4.   <title></title>
  5. <script language="JavaScript1.2">  
  6. //array of non allowed characters
  7. NotAllowed = new Array();
  8. NotAllowed[0]='@';
  9. NotAllowed[1]='!';
  10. NotAllowed[2]='"';
  11. NotAllowed[3]='$';
  12. NotAllowed[4]='%';
  13. NotAllowed[5]='&';
  14. NotAllowed[6]='_';
  15. NotAllowed[7]='(';
  16. NotAllowed[8]=')';
  17. NotAllowed[9]='\'';
  18. NotAllowed[10]='?';
  19. NotAllowed[11]='/';
  20. NotAllowed[12]='\\';
  21. NotAllowed[13]='~';
  22. NotAllowed[14]='°';
  23. NotAllowed[15]='¸';
  24. NotAllowed[16]='}';
  25. NotAllowed[17]='{';
  26. NotAllowed[18]='£';
  27. NotAllowed[19]='¾';
  28. NotAllowed[20]='½';
  29. NotAllowed[21]='¼';
  30. NotAllowed[22]='¬';
  31. NotAllowed[23]='§';
  32. NotAllowed[24]='|';
  33. NotAllowed[25]='¨';
  34. NotAllowed[26]='*';
  35. NotAllowed[27]='<';
  36. NotAllowed[28]='>';
  37. NotAllowed[29]='`';
  38. NotAllowed[30]='´';
  39. NotAllowed[31]='±';
  40. NotAllowed[32]='=';
  41. NotAllowed[33]='-';
  42. NotAllowed[34]='.';
  43. NotAllowed[35]=';';
  44. NotAllowed[36]=':';
  45. NotAllowed[37]=',';
  46. NotAllowed[38]='.';
  47. NotAllowed[39]='»';
  48. NotAllowed[40]='µ';
  49. NotAllowed[41]='¦';
  50. NotAllowed[42]='[';
  51. NotAllowed[43]=']';
  52. NotAllowed[44]='#';
  53. NotAllowed[45]=' ';        
  54.  
  55. var i = 0;
  56. function displaynames(){
  57. heading=document.getElementById('mydiv');//the display div
  58. names='111###22"2###3#33###44"4###55$5###6%66###7&77###8_88###9(99###101 010';//the string
  59.  
  60. nextname = names.split("###");//split names
  61.  
  62. for (XxX=0;XxX<NotAllowed.length;++XxX){
  63. teststring=nextname[i].indexOf(NotAllowed[XxX])+1;//compare string for illegal charaters by looping through array 
  64. if(teststring!='0'){//if an illegal charater has been found 
  65. firstpart=nextname[i].substring(0,teststring-1);//get the first piece of string before illegal character
  66. secondpart=nextname[i].substring(teststring,nextname[i].length);//get the last piece of the string behind the illegal character
  67. nextname[i]=firstpart+secondpart;//rejoin them
  68. else{
  69.  
  70. }
  71. }
  72.  
  73. if (nextname[i]==null){
  74. heading.innerHTML = 'finished';
  75. return false;
  76. }else{
  77. heading.innerHTML = nextname[i];
  78. i++;
  79. setTimeout('displaynames()',2000);
  80. }
  81. }
  82.  
  83.  </script> 
  84. </head>
  85. <body onload="displaynames()">
  86.  
  87. <div id="mydiv"></div>
  88. </body>
  89. </html>
  90.  
  91.  
well let me know what u think
peace

Thanks a lot man for taking the pains in trying to solve my problem...
nice idea of declaring the illegal characters in the beginning ... but thought that the same could have been done easily using the replace function...
also.... in case the string is something like this -> tom'jer"ry
then that code wont work because it will remove ' and combine to give,
tomjer"ry, which can be overcome using the replace function.

anyway... my problem is that i am passing values to the displaynames function and not declaring my string inside, so when the string am passing to the function contains an illegal character it throws an error.doesnt go into the function also in that case.
Apr 17 '07 #17

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Google Mike | last post by:
Tell me if this can be done, and if I have a misconception here. I am writing an app that will be served up in an app farm, and therefore I need to move the session information to the client, not...
2
by: Troy Lynch | last post by:
I'm looking into writing a Category Hierarchy on a site I've written and am looking for some information about writing this kind of code. Maybe some samples or a book. Any information would be...
8
by: Steve | last post by:
Can anyone tell me the preferred method for writing and retrieving persistent information using .Net. Specifically, I am referring to information that you used to see in registry keys or .ini...
4
by: HNguyen | last post by:
Hi, I have a Web application in ASP.NET. My Application allows the users upload files into the server after checking their user names and passwords. For each transaction, the Web program will...
4
by: Gary Bond | last post by:
Hi All, Can anybody point me to some 'how-to' documentation, tutorials, etc as to how to write a shrink/protect wrapper for .Net exes/dlls, (like the Shrinkwrap product for instance). I have...
6
by: JeffDotNet | last post by:
Writing to a registered source in the Application event log I have an asp.net framework 2.0 app that I created on a winxp machine and now I am deploying it to IIS6 on a win server2003 machine. ...
8
by: FM | last post by:
Hello: I want to create a trigger wich performs a write-action to a text file. I'm intending to create it with: CREATE TRIGGER TR_ALARMA_TSPRE AFTER INSERT ON T_ALARMA_TS FOR EACH STATEMENT...
1
by: Julian32 | last post by:
Hello, I'm trying to keep track of purchases made from my website by having Paypal redirect users to a page on my site after purchase, and writing the information received to an Access Database....
5
by: chemlight | last post by:
I'm writing a page that is dynamically created. I'm using PHP sessions, and have run into the issue of sessions timing out when someone walks away from their computer - but they have completed a...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.