473,503 Members | 544 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

need some quick help with this little variable question

hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;

alert(total+setnumber);

</script>

Ok, the alert does not work, but my goal is to do what I hope is
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be accessed/utilized as
such.

Can someone please help me with this? It would be greatly
appreciated. Have a very nice day.

Rebecca.

Jul 23 '07 #1
8 1282
Hi,

On Jul 22, 5:08 pm, rebecca...@gmail.com wrote:
hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;
Is the above line relevant?
alert(total+setnumber);
alert("total"+setnumber);
</script>

Ok, the alert does not work, but my goal is to do what I hope is
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be accessed/utilized as
such.

Can someone please help me with this? It would be greatly
appreciated. Have a very nice day.
You might find this helpful.

<URL: http://www.jibbering.com/faq/#FAQ3_1>

Peter

Jul 23 '07 #2
On Jul 22, 8:08 pm, rebecca...@gmail.com wrote:
hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
You are missing the type attribute (text/javascript.)
var setnumber = 5;
var total5 = 100;

alert(total+setnumber);

</script>

Ok, the alert does not work, but my goal is to do what I hope is
I don't see "total" defined.
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be
Like this?

alert('total' + setnumber);
accessed/utilized as
such.
You lost me there. And why do you have a variable called "total5" set
to 100?

Jul 23 '07 #3
ASM
En réponse ŕ re********@gmail.com qui nous a susurré, en date du :
23/07/07 2:08, le message sibyllin suivant :
>
<script>
var setnumber = 5;
var total5 = 100;

alert(total+setnumber);

</script>

Ok, the alert does not work, but my goal is to do what I hope is
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be accessed/utilized as
such.

alert('total = ' + window['total'+setnumber]);

there is also the function eval()

alert('total = ' + eval('total'+setnumber));

--
Stephane Moriaux et son (moins) vieux Mac
Jul 23 '07 #4
Lee
re********@gmail.com said:
>
hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;

alert(total+setnumber);

</script>

Ok, the alert does not work, but my goal is to do what I hope is
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be accessed/utilized as
such.
The other two answers tell us that your goal is not obvious.

You want to reference a variable whose name is partially
supplied in the value of another variable.

alert(window["total"+setnumber]);

will alert the value of total5, if setnumber=5.

Global variables are attributes of the window object (in a browser).
If your attribute name is the value of an expression, you can use
this "square bracket notation", to access it.
This makes the object look sort of like an associative array.
--

Jul 23 '07 #5
re********@gmail.com said the following on 7/22/2007 8:08 PM:
hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;

alert(total+setnumber);

</script>

Ok, the alert does not work, but my goal is to do what I hope is
obvious, and that is to join the setnumber value with the word
'total', so it becomes 'total5', and so it can be accessed/utilized as
such.

Can someone please help me with this? It would be greatly
appreciated. Have a very nice day.
alert(window['total' + setnumber])

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 23 '07 #6
Peter Michaux wrote:
On Jul 22, 5:08 pm, rebecca...@gmail.com wrote:
>hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;

Is the above line relevant?
>alert(total+setnumber);

alert("total"+setnumber);
That would display "total5". However, it would see the OP wanted to
display "100":

window.alert(this["total"] + setnumber);

I recommend to use an array instead of numbered variables, though.
<URL: http://www.jibbering.com/faq/#FAQ3_1>
You must be kidding.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 1 '07 #7
Peter Michaux wrote:
On Jul 22, 5:08 pm, rebecca...@gmail.com wrote:
>hi, i am still figuring out joins and whatnot, could someone help me
achieve this goal?

<script>
var setnumber = 5;
var total5 = 100;

Is the above line relevant?
>alert(total+setnumber);

alert("total"+setnumber);
That would display "total5". However, it would see the OP wanted to
display "100":

window.alert(this["total" + setnumber]);

I recommend to use an array instead of numbered variables, though.
<URL: http://www.jibbering.com/faq/#FAQ3_1>
You must be kidding.
PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Aug 1 '07 #8
Thomas 'PointedEars' Lahn said the following on 8/1/2007 9:16 AM:
Peter Michaux wrote:
On Jul 22, 5:08 pm, rebecca...@gmail.com wrote:
>hi, i am still figuring out joins and whatnot, could someone help me
>achieve this goal?
>>
><script>
>var setnumber = 5;
>var total5 = 100;
>
Is the above line relevant?
>
>alert(total+setnumber);
>
alert("total"+setnumber);

That would display "total5". However, it would see the OP wanted to
display "100":

window.alert(this["total" + setnumber]);

I recommend to use an array instead of numbered variables, though.
Do you ever read a thread before replying? It has been mentioned several
times before now that an array would work better for what the OP wanted.
<URL: http://www.jibbering.com/faq/#FAQ3_1>

You must be kidding.
Why would referring the OP to buy a book (via hint) be kidding?

BTW, your posting agent, newsserver or your setup is broken for you to
be posting your reply twice.

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 1 '07 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
4642
by: Tom | last post by:
Please help. I need a quick little scrpit to place on a web page that will count how many days have passed since January 1, 1970. I have ZERO experience writing ANY scripts. Anyone have any...
9
4498
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
9
2183
by: Stefan Turalski \(stic\) | last post by:
Hi, I done sth like this: for(int i=0; i<10; i++) {...} and after this local declaration of i variable I try to inicialize int i=0;
9
2558
by: Gordon | last post by:
Hello again, Sorry to repost this request, but I'm under a bit of pressure to find a quick solution. All I basically want is an automatically updating link (OLE, not DDE) between a control in...
21
3324
by: Thelma Lubkin | last post by:
I would like my DLookup criteria to say this: Trim(fieldX) = strVar: myVar = _ DLookup("someField", "someTable", "Trim(fieldX) = '" & strVar & '") I don't believe that this will work, and I...
0
3921
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need ...
9
1953
by: shk253 | last post by:
I've been asked to write a program that calculates the total time worked. I use struct to create variable type time1, and ask the user to enter time in and time out. I convert both to seconds and...
1
1108
by: BryanA | last post by:
I am new to JS and after googling for a little while I couldn't find an answer to my question. I have an ajax JS that auto updates a certain element. The problem is it has to request another page...
0
7203
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
7281
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
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
5014
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...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
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...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1514
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 ...
0
383
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...

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.