Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

passing the value of a checkbok to JavaScript

Posted on 2014-08-04
8
Medium Priority
?
335 Views
Last Modified: 2014-08-04
I have a table and can access the data in the table with

var name =$(this).closest('tr').find('td:eq(1)').text();

$('#dialog-form input[name="empresa"]').val(Empresa);

No problem

However when I try to pass the vale of a checbox:

var name =$(this).closest('tr').find('td:eq(2)').text();

$('#dialog-form input[name="available"]').val(Empresa);

No matter if the box is checked or not it returns an empty value

When I programthe table the checkbox is either  checked or not checked according to some databse value (1 or o)
0
Comment
Question by:robrodp
  • 5
  • 3
8 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40239522
Is this your checkbox?
$('#dialog-form input[name="available"]').val(Empresa);

What is Empresa?

Post some sample HTML
0
 

Author Comment

by:robrodp
ID: 40239539
Ok,,

it should read

$('#dialog-form input[name="empresa"]').val(name);

you can see the script running:

http://parquevehicular.com/panelx/expertxx.asp#
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40239564
This will give you a value of 1 if the checkbox is checked else 0

name = $(this).closest('tr').find('td:eq(2) input').is(":checked") ? 1 : 0

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:robrodp
ID: 40239652
Now it does get the variable but when I do:

if (Ina === '1'){
    $('#dialog-form input[name="ina"]').prop("checked", true);
}

To set the checkbox in with the name ina as, ina='1' it wil always tke the one value, so the ina checkbox is always on.
0
 
LVL 58

Expert Comment

by:Gary
ID: 40239658
If lna is a number then this won't work
if (Ina === '1'){

Use
if (Ina == '1'){
0
 

Author Comment

by:robrodp
ID: 40239683
Same result...

Once ina is set to 1 like it gets trapped
0
 

Author Comment

by:robrodp
ID: 40239702
Sorry,my mistake it does the trick.
0
 

Author Closing Comment

by:robrodp
ID: 40239706
Pretty nifty

Thx
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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

579 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