473,322 Members | 1,307 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,322 software developers and data experts.

variable increment problem

10
This is my code:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Untitled Document</title>
  7. <style type="text/css" id="mainStyle">
  8. #floatingDiv {
  9.     position:absolute;
  10.     border:#000000 solid 1px;
  11.     font-family:Arial, Helvetica, sans-serif;
  12.     font-size:14px;
  13.     margin-top:0;
  14.     padding-top:0;
  15. }
  16. #floatingDiv ul li:hover {
  17.     background-color:#333333;
  18.     color:#CCCCCC;
  19.     cursor:pointer;
  20. }
  21. #floatingDiv ul {
  22.     padding:0;
  23.     margin:0;
  24.     list-style:none;
  25. }
  26. </style>
  27. <script type="text/javascript">
  28. function changeText(value) {
  29.     document.mainForm.textBox.value = value;
  30. }
  31. var li_n = 0;
  32. function populateList(){
  33.     objList = document.getElementById('floatingDivUL');
  34.  
  35.     objListElement = document.createElement('li');
  36.     objTextNode = document.createTextNode('Test Element'+li_n+'');
  37.     if(navigator.appName != "Microsoft Internet Explorer") {
  38.         objListElement.setAttribute("onclick","changeText('Test Element"+li_n+"')");
  39.     } else {
  40.         objListElement.setAttribute("onclick",function(){changeText('Test Element'+li_n)});
  41.     }
  42.     objListElement.setAttribute("id","floatingDivLi"+li_n);
  43.  
  44.     objListElement.appendChild(objTextNode);
  45.     objList.appendChild(objListElement);
  46.  
  47.     CheckEvents();
  48.  
  49.     li_n++;
  50. }
  51. function CheckEmpty() {
  52.     if(document.getElementById('floatingDivUL').innerHTML == "") {
  53.         document.getElementById('floatingDiv').style.border = "";
  54.     }else{
  55.         document.getElementById('floatingDiv').style.border = "#000000 solid 1px";
  56.     }
  57. }
  58. function CheckEvents() {
  59.     CheckEmpty();
  60. }
  61. window.onload = setTimeout("CheckEvents()",10);
  62. </script>
  63. </head>
  64.  
  65. <body>
  66. <form name="mainForm">
  67.     <input name="textBox" type="text" /><a href="javascript:populateList()">clcik</a><br />
  68.     <div id="floatingDiv">
  69.         <ul id="floatingDivUL">
  70.  
  71.         </ul>
  72.     </div>
  73. </form>
  74. </body>
  75. </html>
  76.  
My problem is that the changeText() function where it looks like this function(){changeText('Test Element'+li_n)} does not use the li_n variable where it was initiated but where it is at after incrementation.
Oct 7 '07 #1
1 1512
gits
5,390 Expert Mod 4TB
hi ...

try not to use setAttribute for the onclick, use something like in the following example:

Expand|Select|Wrap|Line Numbers
  1. // this variable 'li_n' must be global and increment it 
  2. // the way you want
  3. var li_n = 0; 
  4.  
  5. function changeText(val) {
  6.     alert(val);
  7. }
  8.  
  9. var click_handler = function(e) {
  10.      var val = 'Test Element' + li_n;
  11.  
  12.      return changeText(val);
  13. };
  14.  
  15. your_obj.onclick = click_handler;
  16.  
kind regards
Oct 7 '07 #2

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

Similar topics

8
by: G. | last post by:
How to increment global xsl:variable? I've daclared variable: <xsl:variable name="my-var" select="0" /> Somewhere else I do something like this: <xsl:variable name="my-var"...
166
by: Graham | last post by:
This has to do with class variables and instances variables. Given the following: <code> class _class: var = 0 #rest of the class
3
by: Pavan | last post by:
Hi i would like to know abt the data variable storage in C like 1.where does global variables gets stored and why is it so .. 2.like wise static ,local variables, as for as i know i remember...
4
by: N. Demos | last post by:
Hello, I'm learning ASP.NET, and am having a strange problem with some example code from the book I'm using. The code increments and displays the value stored in a session variable when the "Add"...
1
by: Nathan Sokalski | last post by:
I am trying to increment the Session variable at certain points in my code, but it will not work. The initial value assigned to it is always the one that is displayed. Here is the code used to...
5
by: Jeff | last post by:
Hey Below is a C# program I've made.... it's an app where I experiment with variable scope. In this code you see two variables named i (one is a local variable and the other is a member of the...
3
by: Goran | last post by:
Hi @ all! Is it possible to overload a member variable? Example: class ClassA_t {
37
by: minkoo.seo | last post by:
Hi. I've got a question on the differences and how to define static and class variables. AFAIK, class methods are the ones which receives the class itself as an argument, while static methods...
2
by: sharonDonnelly | last post by:
Hi Really dumb problem that's got me beat. Can someone help. The prolem: I'm trying to count the number of times an item has been clicked. There are many items. I want to create a session...
11
by: estantep | last post by:
Hello, I am trying to find out an alternate way to brute-force a variable length vector with different variable length contents. int chromossome int max_value_for_each_chromossome
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.