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

How do I access a Javascript variable that is not known until execution time?

Don
Hi,

I jave a form that creates checkboxes dependent on what is selected
from a drop-dwon list; this is done using PHP. I have a button that
allows a user to "SELECT ALL" which will calls a JavaScript function to
check or uncheck all available checkboxes. The thing is, the number
and names of the checkboxes are built at run time and named 'dopost'
plus number like so:

dopost1, dopost2, dopost3, etc...

At the moment, my JavaScript function looks like this:

function selectInvoices(num_bl) {
for (bl_counter=1; bl_counter<=num_bl; bl_counter++) {
var dpvar = 'document.list_invoices.dopost' + bl_counter +
'.checked';
if (dpvar) {
alert(dpvar + ' is Checked');
} else {
alert(dpvar + ' is NOT Checked');
}
}
}

So..., how do I get the variable 'dpar' to reference the form object???

Thanks,
Don

Mar 7 '06 #1
1 1396
Don wrote:
dopost1, dopost2, dopost3, etc...
That's a strange way of naming inputs, I know PHP doesn't know how to
handle fields with the same name, so use the other structure.

<input name="dopost[]" />
<input name="dopost[]" />
<input name="dopost[]" />

On the server it will become an array, which is easier to handle.
But it may be not a good idea too
<URL:http://jibbering.com/faq/#FAQ4_25> =]

At the moment, my JavaScript function looks like this:

var dpvar = 'document.list_invoices.dopost' + bl_counter + '.checked';


This is available on the group FAQ
<URL:http://jibbering.com/faq/#FAQ4_39>.
--
Jonas Raoni Soares Silva
http://www.jsfromhell.com

Mar 7 '06 #2

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

Similar topics

6
by: Andy Fish | last post by:
Hi, I want to use an anchor tag to invoke some javascript and I've read that it's bad form to use <a href="javascript:foo()"> I've read endless usenet posts and hint sites on the net, they all...
8
by: Sergio Otoya | last post by:
Hi all, I need to add an input hidden field to an existing form (post). I have tried a couple things like adding the '<INPUT type=hidden name=idSelectedURL value=http://server/documents>' to...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
16
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
9
by: Phil_Harvey | last post by:
I am redoing my website and trying to get it to do something more exciting using Javascript. I did normal Java at university and code at work in VB.NET. I have got reasonably far into what I want...
2
by: Rob Long | last post by:
Hi there Is there any way to access private variables directly from within a priviliged function? I have a situation where the priviliged function's execution context contains variables of the...
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
3
by: Beamer | last post by:
Hi I am trying to build a roating slide effect in javascript. Basically, I have a list like below <ul id="slideShowCnt"> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li...
3
by: Jonathan Fine | last post by:
As subject. By 'before' I mean before in the file, not in time. Here's a file === $ cat wierd.js f() function f(){print('hi')} f() function f(){print('ho')} f()
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.