473,662 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

writing information to a div

304 Contributor
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(na me)
{
names = name.split("### ");
heading.style.v isibility="visi ble";
heading.style.d isplay = "block";
heading.innerTe xt = names[i];
i=i+1;
var t = setTimeout('sho wnames()',2000) ;
}
function shownames()
{
if (i<names.length )
{
heading.innerTe xt = names[i];
i=i+1;
var t = setTimeout('sho wnames()',2000) ;
}
else
{
i=0;
heading.innerTe xt = names[i];
i=i+1;
var t = setTimeout('sho wnames()',2000) ;
}


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

any help would be appreciated...

thanks,
gomzi.
Apr 14 '07 #1
16 1864
gomzi
304 Contributor
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
DutchKingCobra
37 New Member
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 Contributor
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
DutchKingCobra
37 New Member
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 Contributor
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
DutchKingCobra
37 New Member
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 Contributor
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 Contributor
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
DutchKingCobra
37 New Member
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

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

Similar topics

1
3932
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 using server-side session features. The way I have typically done this in the ASP world was with cookies. Another way to handle this is with a keyed record in a database, but the cookie strategy reduces the number of times I need to hit a...
2
2277
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 helpful. Thanks, Troy Lynch
8
4494
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 files like the name of a database or connection string. I have read several articles indicating that .config files are now used, but I am confused because they are read- only. If I want to write information from within the application (When a...
4
2173
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 write the information about user name, filename upload, filesize, date and time of uploading into the log file. (The name of the log file is constructed by Current Year and Current Month in my program). Is there any problems with writing into the...
4
1755
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 got a couple of products nearly ready for sale, and have already come up with some routines to protect them, (in the style of the old TurboPower OnGuard), but really wanted to shrink and protect the exe's, so as to make reverse engineering a bit...
6
3398
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. This application has to write to the application event log. After deployment of the application I have verified that my source “MySource” exists in the Application event log. I then wrote some text to the event source in a forms app and...
8
7190
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 BEGIN ATOMIC VALUES (SELECT a1,a2,a3 FROM T_TABLE >c:\TRIGGERTEST.LOG); END
1
1540
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. I'm using ASP.NET 2.0, C#, Visual Web Developer 2005. What I do not know is how Paypal returns payment information to the redirect page. Does it post the information to the page? If so what are the individual form value names. Basically I need a...
5
1471
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 large amount of work on one page. I initially thought to use AJAX to pass the current pages information to a PHP page that would just input the information into the database. The issue was, passing the page information using the GET method didn't work...
0
8432
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7365
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4179
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.