PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Mon Sep 25, 2017 10:17 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Mon Aug 15, 2016 9:46 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 170
Hi, this is probably really easy for most of you to spot but I can't figure it out. I have a web page with a form that has a table on it and there is a checkbox column in the table. I also have another column in the table such that if a checkbox is checked on a row this field on the same row needs to be filled out. So I set up an edit shown below. If the 2nd field is not filled out then a popup appears to remind me to fill that 2nd field out. Everything works except for one thing. I only want to execute the edit if the checkbox is true (checked). In my case (because I can't get the test for the checkbox being checked to work) it is executing the edit if the checkmark is removed from the checkbox as well. I have been using the Google chrome debugger. Can anyone spot the error. The code is below with comments to help with a few tests to make sure I am not making any errors other than a syntax error on the specific command.

Thanks,
John


Syntax: [ Download ] [ Hide ]
//My table entry for the checkbox
echo("<input type='checkbox' name='foo[]' value='$fldMS_Key' onclick='funcCheckBIAB($RowCnt)'>  </td>\n");
 


Syntax: [ Download ] [ Hide ]
function funcCheckBIAB(MyRow) {
   var TestX = "X";  

   //Here I am just checking to make sure column 6 is correct and it is.
   TestX = document.getElementById("Table_UpdateSongs").rows[MyRow].cells[6].innerHTML;


   //I am testing to see if the if test detects that the checkbox is true
   if (document.getElementById("Table_UpdateSongs").rows[MyRow].cells[6].checked == true) {
      TestX = "true";  //this statement never gets executed
   }

   //This code is working fine. If I can get the above if statement to work I will nest this code inside the above if statement
   var BIABfile = document.getElementById("Table_UpdateSongs").rows[MyRow].cells[9].innerHTML;
   var BIABFILERight = Right(BIABfile,6);
   if (BIABFILERight == 'NA</a>') {
      CookieName = "YCSJ-No-BIAB-FILE";
      PopupMessage = "You have not entered a BIAB file name.";
      funcDialogPopup(CookieName,PopupMessage);
      return;  
   }

}
 


Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 10:27 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6556
Location: WA, USA
cells[6] is the <td>. You have to get to the <input> inside of it.


Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 11:57 am 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 170
Thanks requinix, althought you didn't give me the answer you got me thinking about the idea that there are objects within objects more or less pointing my thinking in the correct direction so you encouraged me to continue with something I was using before. Specifically a special type of google search shown below.

"document.getElementById( .rows[ .cells[ checked == true"

As you can see it has the generic components of the command designed to pull up examples. When I went through each page and searched for "true" to find a good one quickly.

So I found this example and noticed there were two types of getElement (by ID and by tagName).
document.getElementById(rowid).getElementsByTagName('td')[2].getElementsByTagName('input')[0].checked==true

So then I used the thinking cap and I was able to piece it together and solved it with the final command inside the function below.

I love these puzzles...lol.
Thanks again,
John

Syntax: [ Download ] [ Hide ]
function funcCheckBIAB(MyRow) {
   if (document.getElementById("Table_UpdateSongs").rows[MyRow].cells[6].getElementsByTagName('input')[0].checked==true) {
      var BIABfile = document.getElementById("Table_UpdateSongs").rows[MyRow].cells[9].innerHTML;
      var BIABFILERight = Right(BIABfile,6);
      if (BIABFILERight == 'NA</a>') {
         CookieName = "YCSJ-No-BIAB-FILE";
         PopupMessage = "You have not entered a BIAB file name.";
         funcDialogPopup(CookieName,PopupMessage);
         return;  
      }
   }
}
 


Last edited by bowlesj on Mon Aug 15, 2016 3:15 pm, edited 1 time in total.

Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 12:08 pm 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6556
Location: WA, USA
That's a bit awkward to write, isn't it? Unfortunately it's the best (in my opinion) option... unless you were to start using a Javascript library.

For example, if you used jQuery then you could write
Syntax: [ Download ] [ Hide ]
function funcCheckBIAB(MyRow) {
   if ($("#Table_UpdateSongs tr").eq(MyRow).find("td").eq(6).find("input:checkbox").prop("checked")) {
      var BIABfile = $("#Table_UpdateSongs tr").eq(MyRow).find("td").eq(9).html();

Admittedly it's not much shorter, but it should be quite a bit easier to read.

Either method would benefit from a temporary variable.
Syntax: [ Download ] [ Hide ]
function funcCheckBIAB(MyRow) {
   var cells = $("#Table_UpdateSongs tr").eq(MyRow).find("td");
   if (cells.eq(6).find("input:checkbox").prop("checked")) {
      var BIABfile = cells.eq(9).html();


Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 12:53 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 170
Hi requinix,

I wish I could get into these languages like you obviously are. I did that when I was in my early 40s with unix shell scripting (one of the 17 languages I have learned from a bit to a lot over my programming years from 26 to 62). Yeah, I really enjoyed digging in and knowing every single command from memory and all the regular expression commands from memory. The other language I really got into was assembler (like almost machine language). That was when I was first learning and really excited about programming. I was swapping code in and out of memory for execution. Unfortunately (or fortunately) I got away from programming and ended up retired early. I have gotten back to music (I taught guitar from ages 15 to 25+ with some overlap with programming). At age 59/60I had the strong desire to put together a website to bring musicians together so I took a year, learned 7 languages (as much as I needed to only) and made it happen (completed the website with no fancy cosmetics - not great to look at). When you are in a rush like that you can't really dig right into the language deeply (impossible or you would never get the website finished fast). So you have to get really good at google searches to find examples and use the thinking cap (luckily it seems to still be working...lol...as far as I can tell). I hate asking people questions actually. It is a combo of respecting people's time and enjoying solving it myself. Yeah, I had one language I was learning called "Power Language" which was a scripting language for a program called "MultiCharts" for trading the markets. There was one problem that took me 3 solid (and I do mean solid) weeks to finally resolve. I asked no one for help. Google did not help. It was solved without (without) a debugger too. It was a strange quirk in that language that made it so difficult and everyone had that problem with it. That was by far the worst. It turned out that no one could have helped but I did not know that at the time. It is interesting that the most difficult problem was with a bizarre scripting language rather than a lower level true language. Getting back to the web programming languages, Jquery was the hardest language for me while putting together the website. I don't know it well enough and as a result I find it really confusing at this point. I try not to loose sight of my goals and get dragged in to deep into the enjoyment I seem to have getting immersed as I did with unix shell scripting in my 40s. Anyway, my website failed but I tried a smaller variation on the idea which appears to be popular so I am digging out the code using Xampp and adding a few features to the website and getting them to run (should be all done this week). I will see just how popular it gets and if I can't handle the data entry I will be doing for the musicians and if I can make enough money too I will put it out on the web again so they can do the data entry (I will have to dig through my notes again). Being music I can't see it getting popular enough that I could afford to hire web based programmers who know their stuff as well as you do. However. if it does and if it spreads to other cities (right now 20 in Toronto have shown interest within 4 months) and if I can't handle the load of being programmer and manager I might have too or I might sell it. Time will tell. If I sell it I might sell it to a Jazz guitar student I had recently for two years who has gone into computer programming for a living.

Thanks again, I will try not to ask too many questions (only if I am really stuck).
John


Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 4:17 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13427
Location: New York, NY, US
bowlesj wrote:
Thanks again, I will try not to ask too many questions (only if I am really stuck).
John

We don't mind questions...

_________________
(#10850)


Top
 Profile  
 
PostPosted: Mon Aug 15, 2016 4:57 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 170
Thanks Christopher. I will make sure I don't struggle for 3 weeks ever again :-) I have never had that much trouble with PHP and Javascript. They are easier because they make sense. I could see myself getting stuck on Jquery for 4 weeks...lol. Like Warren Buffet who stays away from investments he does not understand I tend to avoid Jquery :-)

John


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 9:48 am 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13427
Location: New York, NY, US
bowlesj wrote:
I could see myself getting stuck on Jquery for 4 weeks...lol. Like Warren Buffet who stays away from investments he does not understand I tend to avoid Jquery :-)
:D
Honestly, there are very few things I would recommend that you add to your technical portfolio -- jQuery is one of those few. I can't think of anything else a PHP programmer can learn that give more return on investment than jQuery. It makes hard stuff easy. And it allows you to easily move presentation layer code from PHP to Javascript in you templates. That opens up a lot of interesting opportunities. Warren Buffet would approve.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Tue Aug 16, 2016 8:21 pm 
Offline
Forum Contributor

Joined: Fri Jul 18, 2014 1:54 pm
Posts: 170
Thanks Christopher, I guess it is just a matter of time and I was probably jumping into jquery too advanced too fast.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group