Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: Is it possi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 14 Topic 35552 of 37128
Post > Topic >>

Re: Is it possible to create dynamic var

by Thomas 'PointedEars' Lahn <PointedEars@[EMAIL PROTECTED] > May 11, 2008 at 11:00 AM

DL wrote:
> On May 10, 10:34 am, Thomas 'PointedEars' Lahn <PointedE...@[EMAIL PROTECTED]
>
> wrote:
>> DL wrote:
>>> For instance,
>>> function addNew(i) {
>>> var 'element'&i
>>> ..
>>> }
>>> If possible, how to?
>> While eval() is a possibility, and a bad one at that, chances
>> are that you really don't need what you want.  Consider this:
>>
>>   function addNew(i)
>>   {
>>     var a = [];
>>     a[i] = 42;
>>     ...
>>   }
> 
> Thank you both.  I kind of like the above approach, it does not seem
> to solve the problem.

The problem is that you are apparently resistant to studying for yourself.
You will not achieve anything until you solve this problem.

> Here's more detail:
> 
> function addNew(i) {
>  var newF = do***ent.getElementById('tbl');
>  var a = [];
>  a[i] = newF.insertRow();
>  //  ...
>  }
> 
> The above code failed.

A useless error description.  See also
<http://jibbering.com/faq/#FAQ4_43>.

And that it failed is unlikely, since it is syntactically correct since
JavaScript 1.3 (NN 4), JScript 2.0 (NT 4), ECMAScript Ed. 3.  It is more
likely that you don't know what you are doing, and therefore you have used
it wrong.

What replaces the ellipsis matters here.  You may have expected `a[1]' to
be
accessed as `a1' later which is not the case.  My solution provides you
with
a way to let go of several numbered variables and to use an array data
structure instead.

> A related question, how to increment a value?
> The following won't work

See above.

>  // the i value is param for a function like the above one, not be
> concerned
>  var rowCount = 1;
>  rowCount = eval(rowCount + i);

RTFM.  The above *equals* the most simple

  rowCount = rowCount + i;

or

  rowCount += i;

That is, provided `i' is a number value.  If it is not, you will observe
NaN
as result or string concatenation instead (e.g. rowCount === "14" if i ===
"4").  To convert a value to the number type explicitly, there are several
ways.

RTFFAQ: http://jibbering.com/faq/#FAQ4_21

>  alert (rowCount);

Should be

  window.alert(rowCount);


PointedEars
-- 
var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
)  // Plone, register_function.js:16
 




 14 Posts in Topic:
Is it possible to create dynamic var
DL <tatata9999@[EMAIL   2008-05-09 20:53:12 
Re: Is it possible to create dynamic var
Laser Lips <loudsphier  2008-05-10 07:31:42 
Re: Is it possible to create dynamic var
Thomas 'PointedEars' Lahn  2008-05-10 16:34:48 
Re: Is it possible to create dynamic var
Laser Lips <loudsphier  2008-05-10 07:41:48 
Re: Is it possible to create dynamic var
DL <tatata9999@[EMAIL   2008-05-10 15:00:08 
Re: Is it possible to create dynamic var
Thomas 'PointedEars' Lahn  2008-05-11 11:00:56 
Re: Is it possible to create dynamic var
VK <schools_ring@[EMAI  2008-05-10 15:45:03 
Re: Is it possible to create dynamic var
Dr J R Stockton <jrs@[  2008-05-10 22:28:45 
Re: Is it possible to create dynamic var
DL <tatata9999@[EMAIL   2008-05-10 19:06:13 
Re: Is it possible to create dynamic var
DL <tatata9999@[EMAIL   2008-05-10 20:32:57 
Re: Is it possible to create dynamic var
Andrew Poulos <ap_prog  2008-05-11 13:51:11 
Re: Is it possible to create dynamic var
VK <schools_ring@[EMAI  2008-05-11 00:36:02 
Re: Is it possible to create dynamic var
Thomas 'PointedEars' Lahn  2008-05-11 11:11:06 
Re: Is it possible to create dynamic var
DL <tatata9999@[EMAIL   2008-05-11 07:37:43 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Oct 10 14:01:30 CDT 2008.