Putting A Variable In A Variable Name?

May 22, 2009

the following block of code is for demonstrative purposes only:

for (x=0;x<=2;x++) {
game + x = "Game "+x;
}

Okay so looking at that you can probably get the feeling for what I want to do. why I want to do this, as obviously the above code makes no sense and can be done with arrays, but I assure you I have a purpose for doing what I want to do.

The question is, can I put a variable, like x, into a new variable's name? The idea is that the code above generates three new variables:

game0
game1
game2

I've tried using brackets and parentheses, I've tries so many things. I've even tried using the eval() function.

So, again, in short, can I place a variable into another variable's name?

View 10 Replies


ADVERTISEMENT

Putting The Contents Of An Array Into A Variable?

Mar 30, 2010

I was wondering if it is possible to put all the non null variables of an array into a string variable with spaces between each array value? For example, if array() is a text array and has 10 values, array(0) through array(9), with three of those values null, let's say array(3), array(5), and array(7) are null, is there a way to put the remaining seven values into a string variable with spaces between each array value?

View 2 Replies View Related

Putting Javascript Variable Into Hidden Field

Jul 6, 2006

I wish to use J.S. to obtain the screen ht and put this value into a hidden
field for posting. so that I can then use it in a php file.

A simplified script of what I am trying to do is below, but it doesnt work.
I have not used javascript much and I'm sure its straight forward.


<script type="text/javascript" language="javascript">
var ht = document.body.clientHeight;
</script>

<form action="my.php" method="post">
input name="screenht" type="hidden" value="ht"
</form>

View 5 Replies View Related

Question About Putting Variable In Style Change Script

Oct 13, 2006

How do I do something, where

var x="-20%";

document.all("something").style.top=x

normally, this would work --

document.all("something").style.top='-20%'

but the above formulation doesn't..... is there some diff way?

View 2 Replies View Related

Declare A Variable Inside A Function - Returns White Space - Not Variable Value

Aug 17, 2010

I am trying to declare a variable inside a function and use it later on in my code... but it just already returns white space... i.e. not variable value. I am setting it within this function:

function show_video1(){
document.getElementById('video1').style.display="block";
var video1Name = "Education World News (Part 1)";
document.getElementById('video2').style.display="none";
document.getElementById('video3').style.display="none";
document.getElementById('video4').style.display="none";
[Code]...

and trying to call it later on with this: <script type="text/javascript">document.write(video1Name)</script> It might be worth noting that each one of my 11 videos will hace a different name.

View 13 Replies View Related

JQuery :: Specifying Variable In Parent To Match Variable In Ajax File

Oct 21, 2011

Ok, so I've built a member search using ajax to change the results each time a filter is changed. It works great, except one minor issue that I'm struggling with...I just can't specify dynamically in the parent file that linkclass$id opens linkclasscontent$id as I don't know of any way to pass that $id variable back over to the parent.

View 3 Replies View Related

Onclick Defined Variable - Print Variable Some Place In Document

May 28, 2007

i'm not really sure how to explain this, since I know nothing about javascript, so i'll try and illustrate by the use of php (hope it makes sence)

I have a set of different links, like:

<a href="link.com?page=text1">text 1</a>
<a href="link.com?page=text2">text 2</a>
<a href="link.com?page=text3">text 3</a>
etc, where page is dynamic and can be anything I chose..

Another place in the same document, I echo out what the page variable is, like:

echo "$page";
so when clicking "text 1" the echo will output what i've defined the page to be, in this case "text1" ..

So I want to be able to click the links and change the output of the echo all depending on what i've defined in the link - without refreshing the page!

Is there any easy way to do this?

View 2 Replies View Related

ChangeYear - GetFullYear - SetFullYear Functions - Extract The 4-digit Value From The Today Variable And Store The Value In A Variable Named Year

Oct 13, 2009

a.) specify two parameters for the changeYear function: today and holiday.

function changeYear(today)(holiday){

b.) in the first line of the above function, use the getFullYear() date method to extract the 4-digit value from the today variable and store the value in a variable named year.

first line

c.) in the second line; use the setFullYear() date method to set the full year of the holiday date object to the value of the year variable.

second line

d.) in the third line, use a conditional operator on the year variable. The test condition is whether the value of the holiday date object is less than the today date object. If it is, this means that the event has already passed in the current year and the value of the year variable should be increased by 1.

third line

e.) in the fourth line of the function, again set the full year value of the holiday date object to the value of the year variable.

View 3 Replies View Related

Setting Variable Equal To Php Variable By Passing A Parameter?

Aug 12, 2011

Code:I am having problems with the following. I am wanting to hide <tr> in my table (employees) and only show employees that are in the selected department (selected via dropdown box).I need to set a javascript array to a php array. I am looping and assigning the array and am wanting to pass a javascript variable as the index in php array. I have marked my problem lines in red. Thanx for any help.

<script type="text/javascript" >
function display_elements()
{
var departments = new Array;

[code]....

View 1 Replies View Related

Global Variable Glitch - Can Only Access The Variable On The Second Call

Dec 9, 2011

I am simply trying to use a global variable in javascript, but can only access the variable on the second call. I can't find anything that relates to this through my searches. My application is supposed to query the server for XML that tells me which years and months are available to put into combo boxes. I want to store this xml in a global variable to access it later.

[Code]....

View 6 Replies View Related

External File The LoadTabs Variable Will Not Allow To Pass It A Variable

Dec 1, 2009

I start outside of the external JS file by: reviews.init(); reviews.initialiseContent('comment'); This loads my data and loads + sets the comment tab as default. My problem is that in the external JS file (shown below) the loadTabs variable will not allow me to pass it a variable: contentDiv.onclick = this.initialiseContent; Whenever I pass a variable here it errors, am I setting this up correctly, should I be using prototype for my this. variables? Interested to hear back on if this structure of code is the right way to go about this and also how I can pass a variable in this way :)

[Code]....

View 2 Replies View Related

JQuery :: Defining A Part Of A Variable With Another Variable?

May 15, 2011

I am trying to define a variable as follows:

var music_id = $(this).attr('id');
var mix_class = $('#le' + music_id);

In other words, if music_id is mix3, I want mix_class to be #lemix3.The above code is not working for me and I would like assistance as to the syntax to produce such a result

View 2 Replies View Related

Pass Dynamic Php Variable To Script Variable?

Jun 9, 2011

I tried this code but i got an error on the it said Syntax error code...

View 6 Replies View Related

Undefined Variable Error, Even Though Variable Is Defined?

Aug 24, 2010

I have a php page in which I declared a js variable... right at the top of the page...

<script type="text/javascript">
var tester = 0;
</script>

[code]....

View 2 Replies View Related

Get A Variable From A Remote Page And Define As Variable?

Apr 26, 2011

I have a programing problem that have been around for ages. I have search on google using several expressions and words and after hours of digging i'm still unable to do it.I would like to get a value from a HTML page hosted remotely with an inconstant value. Then define this value and name as a javascript variable and apply or show in my page.P.S. Is there any way to make a domain lookup in javascript? I mean a user enters a domain and the script converts to an ip and shows to the user. If not thanks, probably it can only be done in the server side...

View 6 Replies View Related

JQuery :: $("selector" - Code) And .html() - Load Div In A Variable - Modify It In Another Variable And Then Change The Document Injecting The Contents

Dec 13, 2011

I want to load an html div in a variable, modify it in another variable; and then change the document injecting the contents.

1. I load the html to be changed in a variable (code)
2. I modify an attribute of <param> using attr() and I put the result in a var (newcode)
3. I change the html in the doc

I've used the debugger, and all steps give the expected results, except of newcode.html(), which is a null string. Why?

[Code]....

View 8 Replies View Related

Variable To Form Hidden Variable's Value

Nov 14, 2010

I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function. I need to send this variable as the value of a hidden field in the form which is in the body of the document.

This is my JavaScript Code:

Code:

And at the end of my form, before the submit button, I have the following code:

Code:

When I execute the form, it doesn't work the way it should, plus, gives me a word "undefined" next to the "Submit" button .....

View 1 Replies View Related

Odd Variable Behavior - Changing One Variable Changes Another

Oct 16, 2009

I'm trying to create an array of dates two weeks apart from an arbitrary startDate, and I've noticed some odd behavior in my variables. I did a little experiment on my JS console and here's what I got. My inputs are in blue, the output is in black.

Code:

Everything's good so far, but here's where it gets odd. I try to add 14 days to cur.

Code:

Why is it that when I make changes to cur, the same changes are made to startDate?

View 7 Replies View Related

Possible To Pass Script Variable To Php Variable?

May 6, 2010

Is it possible to assign a javascript variable to a php variable without using forms?

I want to display the variable address where I have stored the users address which I got from the google maps geocode and I want to display it inside a div. code...

View 2 Replies View Related

Add The Values Of Several Variables In One Variable And Then Use This Variable

Sep 21, 2010

I want to add the values of several variables in one variable and then use this variable, which contains the values of variables

You can see the following example

HTML Code

PHP Code:

Javascript Code

PHP Code:

After executing this code I find that the variables are not displayed values

As in the following picture: [url]

View 3 Replies View Related

Set Time As Variable Or Global Variable?

Sep 6, 2011

I am creating a survey. I want to set a variable, which is sent to google analytics, as the current time. this is the code and works fine:

HTML Code:
<script type="text/javascript">
<!--
var d1 = new Date();
var curr_date = d1.getDate();
var curr_month = d1.getMonth();

[Code]...

View 1 Replies View Related

Variable To Form Hidden Variable's Value?

Nov 14, 2010

I have a javascript in the head of the document which has a variable named "ref2" ... ref2 is already working as I can see its value working in another function.I need to send this variable as the value of a hidden field in the form which is in the body of the document.This is my JavaScript Code:

function WriteContactFormStatement1 () {
var ContactFormValue = ref2;
document.write('<input type="hidden" name="UReferrersName" value="' + ContactFormValue + '"

[code]....

View 2 Replies View Related

JQuery :: Css Class As Variable - Change The Css Class Of Li Element From Name Hidden To Variable FilterVal

May 26, 2010

I just donīt know the right syntax for this:

I want to change the css class of the li element from the name hidden to the variable filterVal, but i donīt know the right syntax.

View 1 Replies View Related

How To Get Javascript Variable Value Into Asp Variable

Jul 23, 2005

if I have both javascript and aspscript,

how to get/retrieve the variable value in javascript into asp variable ?

View 4 Replies View Related

Passing Variable To PHP Variable?

Mar 26, 2009

Basically I have a javascript variable... var caption... I need to get that into php so I can run a mysql_query... I then need to get the result back in to javascript...I can do the last bit... In fact I have it almost working except the first bit... Here's the code...

function showpic (args) {
var argsarray =args.split ("_SPLIT_");
var imgurl =argsarray[0];
var caption =argsarray[1];

[code]....

The end result needs to be this... I need to lookup if the value in var caption is in the jos_jxzine_articles database... Then I need to return the id from the appropriate row as a argument for shadowbox.open...

View 3 Replies View Related

Inserting A Variable Into A Variable Name?

Nov 15, 2009

I am having a problem where I want to change a particular variable based on what parameters I send to a js function.

In the code below, dnum is a number 1-6, and I want the global variable d1keep (or d2keep, d3keep etc.) to equal the dvalue.


function KeepDie(dnum, dvalue) {
d+dnum+keep=dvalue;

[code]...

I've tried using single quotes, double quotes, brackets, curly brackets, parentheses, and other punctuation in many locations all over that line of code, but I cannot get it to work.

View 6 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved