Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Getting checked value from a checkbox in html table  RSS feed

 
Michael Valens
Greenhorn
Posts: 4
Firefox Browser PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a JS "advanced beginner". I have a HTML table id=results_tbl generated in PHP; one of its columns is:




I try to determine which rows the checkbox has been clicked using this JavaScript code:



Problem: When I run the JS code, I only get Checked = false, even if some check boxes are checked.


Thank you

Mike
 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see you checking if the checkbox is checked?
If you think you're doing that on line 17, you're not checking if the checkbox is checked, you check it.
To check it would be:


This is not working code of course it's just to dominstrate.
It's also unclear to me what you're trying to do with that if statement, you first check if the length of cols is bigger then 1 but then you direct a specific column (8)?
 
Michael Valens
Greenhorn
Posts: 4
Firefox Browser PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Daniel,

Actually, the line where I check looks like this:



With the above, I think I am checking the checkbox in every line, aren't I ?

And I always get false.

Mike

PS. How can I edit a post AFTER i submitted it ? I mean, to correct an error or something.
I can't see any [Edit] button on the page.

 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Valentin wrote:Hi Daniel,
Actually, the line where I check looks like this:


And that's line 17 in the code you posted, so remove the and put it in a if statement.

note: this can't work, since isn't a textfield but a checkbox.

With the above, I think I am checking the checkbox in every line, aren't I ?  


with this you're checking every row:

My guess is that your checkboxes are in the 8th column?
So this if statement is useless:

But to really be able to help I would like to see the rest of the code and your html, cause somethings you try to do seem weird to me

Editting posts is something you have to earn by gaining reputation. I think you have to be ranch hand (40posts), but it could be you have to be ranchforeman or rancher, those are eaned titles.
Ranchforeman is given by girbot, to the most active members and rancher by the mods.
for more info about titles have a look at this post about saloontitles.
If there is something small you wanna change, you can always ask the mods, but keep in mind, they're verry bussy, or post a correction afterwards.

And by the way, welcome to the ranch...
 
Michael Valens
Greenhorn
Posts: 4
Firefox Browser PHP Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Daniel.

I edited my code using your idea, now it looks like this:



It works now !


I also added a special button to run function CheckChecked() ONLY when I press that button.
Previously the code was attached to the $(document).ready(function(), so it was run every time I pressed the form's Submit button.

The form reads a MySQL table, creates a HTML table where cells should be edited - I'll try in-place editing, have never done it before :).

Then it will update the MySQL table via XHR (also never tried it before).


Thank you,

Mike


 
Daniel Demesmaecker
Master Rancher
Posts: 1161
18
Firefox Browser Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need npm to make a connection with a mysql db... XHR is to connect to a webserver
 
I got this tall by not having enough crisco in my diet as a kid. This ad looks like it had plenty of shortening:
ScroogeXHTML 8.2 - easy to use RTF to HTML converter library
https://coderanch.com/t/707504/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!