[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I check to see if this box is checked in Javascript?

Posted on 2014-03-06
9
Medium Priority
?
110 Views
Last Modified: 2014-03-07
Here's my HTML:

<input type='Checkbox' name='deleteCapX3' value='226' 
                    onclick='delete_visibility(dfm,"3","3");'>

Open in new window


Here's my function:

function delete_visibility (form, row, count) {
 var var_ticker=0;
 var numRows = form.allocatedlistcount.value;
 if(form.deleteCapX'+row+'.checked)
 {
     alert("Yeah!");
 }

Open in new window


If I write my code like this:

if(form.deleteCapX3.checked)...

...it fires fine.

But if I want to grab the row number that's been passed into the function ("row), how do I write that? When I try form.deleteCapX+row+ I get an error and I can't figure out how to write it.

Thanks!
0
Comment
Question by:brucegust
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 39910118
<input type='Checkbox' name='deleteCapX3' value='226'
                    onclick='delete_visibility(this,dfm,"3","3");'>

function delete_visibility (ref,form, row, count) {
 var var_ticker=0;
 var numRows = form.allocatedlistcount.value;
 if(ref.checked)
 {
     alert("Yeah!");
 }
0
 

Author Comment

by:brucegust
ID: 39910131
Leak, your suggestion is spot on, but I've got to code it like I've got it because I'm ultimately running everything through a loop, so I've got to figure out how to tack on to that form.DeleteCapx variable a number. I've tried the following:

form.Delete.Capx'+row+'.checked
form.Delete.Capx"+row+".checked

...and several other combos and nothing's working.

Any suggestions along those lines?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39910150
It's because you've random reference that you should use this
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 9

Accepted Solution

by:
Sar1973 earned 1400 total points
ID: 39911902
You should use the eval function if you want to declare a variable assigning to it an index:
eval("var form.deleteCapX"+row+".checked;");
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 600 total points
ID: 39912142
You should use the eval function if you want to declare a variable assigning to it an index

don't do that!!!
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#Don.27t_use_eval.21
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39912177
Needlessy, it says...however, how can you declare a variable in a loop in which it depends on its index?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 39912238
however, how can you declare a variable in a loop in which it depends on its index?

@Sar1973 : Create a new question, I will be happy to answer it :))
0
 
LVL 9

Expert Comment

by:Sar1973
ID: 39912277
I refer on my previous answer (see also http://www.w3schools.com/jsref/jsref_eval.ASP).
0
 

Author Comment

by:brucegust
ID: 39912576
Thanks guys! As always the insight and even the professional sparring is appreciated in the way it brings to light the answer needed in order to serve the client.

Here's what worked:

 for( var rowIndex = 1; rowIndex <= numRows; rowIndex++ ) {
 eval('deletecb = form.deleteCapX'+rowIndex+'.checked;');

Granted, it's an eval which, according to some, is cancer on wheels, but it works and is consistent with the conventions that are being used on the project I'm working on. So, rock on, boys, rock on!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question