1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

HTML check box select change row color

Discussion in 'jQuery' started by Azzam Qazi, May 14, 2015.

  1. #1
    I need some help please.

    Below is my code for an HTML table.

    It has multiple checkboxes.

    What i want to do is that once the "HOLD"check-box is clicked, I want to grab the Piece ID field for the selected row so that I can do some AJAX using that number.

    Can someone please help me out

    Thanks.

    <tableid='consignment_list'class="consignment_list_tbl"><colgroupwidth='20'></colgroup><?php
    if($user->getUserAccount()=="") echo "<colgroup width='30'> </colgroup>";?><!-- table head --><thead><tr><th>Select All <inputtype='checkbox'name='checkall'onclick='checkedAll(deleteConsignments1);'></th><th>Status</th><?phpif($user->getUserAccount()=="") echo "<th>Account</th>";?><th>Packages</th><th>HAWB</th><th>AWB</th><th>Consignee Name</th><th>City</th><th>Country</th><th>Weight</th><th>No of Pieces</th><th>Piece ID</th><th>Hold</th><th>Heavy Weight</th></tr></thead><!-- table foot --><tfoot><tr><td>&nbsp;</td><?phpif($user->getUserAccount()=="") echo "<td>&nbsp;</td>";?><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr></tfoot>

    <!-- table body -->

    <tbody><?phpforeach($consignment_array as $ct_idx => $consignment){foreach($consignment->getParcels(true)as $parcel){if($parcel->getProcessed()==1){continue;}

    $status = $consignment->getStatus();
    $id= $consignment->getId();?>
    <tr style="background-color: red;color: black;" id="<?php echo $parcel->getLicencePlate()?>"
    name="<?php echo $consignment->getAwb()?>">
    <tdid="c"> <input type=checkbox id= "deleteConsignments1"
    name="deleteConsignments[]" onclick="row_color(this)" value="<?php
    $consignment->getId()?> " /> </td>

    <td><?php echo Consignment::stateText($status);?></td><?phpif($user->getUserAccount()=="") echo "<td>". $consignment->getAccount()."</td>";?><tdclass="colPieces"><?php echo $consignment->getNumberPieces();?></td><td><a href='../main/consignment_edit.php?from=client&id=<?php echo
    $consignment->getId();?>' style="color: white;">
    <?php echo $consignment->getHawb();?></a></td><td><?php echo $consignment->getAWB();?></td><td><?php echo $consignment->getContact();?></td><td><?php echo $consignment->getCity();?></td><td><?php echo $consignment->getCountry();;?></td><td><?php echo $consignment->getWeight();?></td><td><?php echo $consignment->getNumberPieces();?><td><?php echo $parcel->getLicencePlate();?></td><td><input type=checkbox onclick="row_colorHold(this)" name="hold[]"
    id="hold1" value="<?php echo $consignment->getId();?>" ></td><td><input type='checkbox' name='heavyweight[]' id="heavyweight" value="<?
    php echo $consignment->getId();?>"></td></td></tr><?php
    }}?></tbody></table>
     
    Last edited: May 14, 2015
    Azzam Qazi, May 14, 2015 IP
  2. Azzam Qazi

    Azzam Qazi Greenhorn

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    below is the fiddle jsfiddle.net/fhgmsg5L I want to fetch the piece ID of the selected row using the "HOLD" checkbox
     
    Azzam Qazi, May 14, 2015 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #3
    Well... you should have a proper form and such, but apart from that, just do something like:
    
    $('element_with_hold_checkbox').click(function() {
    //check to see if it's checked or not, perhaps, but:
    getID = $(this).parents('tr').attr('id');
    });
    
    Code (markup):
     
    PoPSiCLe, May 14, 2015 IP
  4. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #4
    Rather than grab the ID, why not just grab the parent TR by walking the DOM? Oh that's right, you're using the jQuery BS so you aren't learning how JS is supposed to be written.

    ... as evidenced by the presence of onchange attributes instead of hooking the DOM.

    I mean if you know the checkbox is the only child of that TD, just grab the target/srcElement's parentNode.parentNode -- and that should be the TR.

    Without the jQuery idiocy:

    function checkHandler(e) {
    	e = e || window.event;
    	var
    		t = e.target || e.srcElement,
    		parentTR = t.parentNode.parentNode;
    	/* process whatever you want to do to the parent row here */
    }
    Code (markup):
    Don't even waste time with ID's or selector BS, you shouldn't need that except MAYBE classes to target the input with, and even then you SHOULD be able to do that by walking the DOM or getElementsByTagName and checking for 'name'.

    I swear, jQueery just turns developers into halfwits with it's actively encouraging sloppy slow bloated coding habits and preventing people from learning how anything actually works. WHY THE HELL do people use this CRAP?!?

    I'd probably also axe the colgroups since they are poorly supported cross browser (see the STILL unfixed bugzilla 915) and get some SCOPE attributes in there, possibly changing the row name inside TBODY to a TH as well. Again, until you have proper semantic markup don't waste time dicking with scripting.

    Also, TR don't HAVE name attributes.
     
    deathshadow, May 17, 2015 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    People use it because that code, in jQuery, would be this:
    
    $('whateverelement').click(function() {
      $(this).parents('tr').doStuffHere;
    });
    
    Code (markup):
     
    PoPSiCLe, May 18, 2015 IP
  6. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #6
    Which hides how it really works, seems needlessly cryptic, doesn't actually seem to give you the element so you better hope jQ actually provides methods for what you want to do with the element, and the handful of bytes allegedly saved aren't worth the ridiculous code bloat, painfully slow execution time and general "what the **** is wrong with you people" code that results.

    Seriously, I just don't get the appeal of some bloated library that minified is larger than I'd allow the HTML+CSS+SCRIPTS for an entire page to reach without minification just so you can have this idiotic memory wasting CPU wasting daisy chain of re-re halfwit cryptic garbage that doesn't let you ACTUALLY use the underlying language properly. It's some serious herpafreakingderp that ANYONE would use jQuery by choice apart from utter and complete ignorance.

    I mean seriously, a object method performing a search to do what you already should know exists as properties of each element? Next you'll be telling me to pass everything as objects to every method and manually calling the equivalent of the native getElementxxx commands every time you have a event handler.

    Which is more mouth-breathing idiocy I see from the jQuery crowd almost daily, then they wonder why their sites are slow inaccessible train wrecks and why as a USER when visiting such sites I have the overwhelming urge to commit a war crime against the development community.
     
    deathshadow, May 18, 2015 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    Well, we just have to agree to disagree about the "more cryptic" - I don't get how you think jQuery is more cryptic than pure javascript (granted, pure javascript makes sense if you sit down and go through the specs, but lets face it, very few people have the time or inclination to do just that). I'm not saying jQuery is better, I'm just providing a reason why people use it - it is easier - the syntax in jQuery is more alike PHP, for one, than pure javascript, hence it's probably easier for people not coming from C<whatever> to work with. I dunno. Personally, I use jQuery because I haven't bothered sitting down and doing the same stuff in pure javascript, simply because it would take me too long to write every helper-method from scratch - especially for more advanced interactions - but then again, you wouldn't use said interactions on a web-page to begin with, hence you don't see the point ;)
     
    PoPSiCLe, May 18, 2015 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #8
    I don't see that at all. When people call it easier I just stand there jaw open in disbelief...

    Gehugafugah? What? Not even CLOSE?!? I see no resemblance really to any real programming language excepting perhaps chain/stack type languages which were effectively killed off two decades ago for a reason.

    That idiotic daisy-chaining of responses and methods (leaving you baffled as to which is actually which) is the pinnacle of "wait, what order is this even executing in?!?"

    True enough -- 99.99% of what people do with jquery continues to fall into three categories for me; things that would be smaller or more efficient without the bloated library, things that are CSS' job, or things that don't belong on websites in the first damned place.
     
    deathshadow, May 18, 2015 IP
  9. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #9
    Granted, daisy-chaining 10+ something in jQuery can be somewhat annoying, but as for the simple selectors $('#id'), $('.class') - they look pretty much the same as they do in CSS. The prefix $ looks like variables in PHP, and the function declaration is quite similar as well. To me, jQuery looks quite alike to PHP (loosely typed, indeed). But yes, using normal javascript can often (maybe always) be a better choice, simply because you avoid having the library in the background - but given that most people today working on web or web-like projects are mostly self-taught, finding information (easily understood information) on jQuery is often a lot easier than finding out how to do the same thing in javascript. Hence, people chose the easy way - jQuery, maybe a plug-in, and voila, a "working" example. Not necessarily following standards or good coding practices, but it works - which to most people is the important bit. Granted, "works" is a bit of a misnomer, but MOST users just use their standard browser (it being IE, Chrome or FF (or, Safari *shudder*)), without so much as a plugin installed. They don't know, and don't care about code that doesn't follow guidelines. Is that a good thing? No, mostly not. But the majority of coders don't care about the few percent that surf with scripting turned off, or using a screen-reader - unfortunately for those people, of course. While I'm all for providing good, clean code, I'm not always inclined to say coding everything from scratch is the right approach, especially if you're trying to do something you're not familiar with - acknowledging that fact, finding something that's already made, and utilizing that, might be the best approach - at least to get the project done. Fatalistic? Maybe. Realistic? Definitely.
     
    PoPSiCLe, May 19, 2015 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #10
    Which to me means they don't even ****ING care about DOING THEIR ****ING JOB!!! -- in which case WHY THE *** ARE THEY MAKING WEBSITES?!?

    I mean at that point, go flip burgers or something. :p

    Lazy sleazeball scumbag piles of filth. Can't we just line them up against a wall or something?
     
    deathshadow, May 19, 2015 IP
  11. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #11
    It's about making money - if you can make money catering to about 80% of user's out there (give or take a few percent depending on market and where you're located), and you can achieve that without going into the whole development process in-depth, then of course you'll chose that route. "Close enough" is often a chosen standard, and unfortunately, W3C and others are often considered extremely slow and outdated. Modern browsers show this as well, in different ways - the problem is often also that there isn't ONE standard - there are 30 standards, not all of them even remotely compatible with eachother.

    I know it's a fatalistic view, but more often than not it's about putting something that sorta works out there - you don't really have much time, you don't really have a budget, and you definitely don't have the time/money to get a hold of someone competent. Then you go with someone that promises you what you need within the limited timeframe you have, and you don't really care if it means that a few percent of your potential customer pool can't use the site. Especially if you never even hear from anyone complaining about it. If it looks good in FF, Chrome and IE, provides a working mobile interface, then most people will be "this works". It's not in any way good, but it'll do the job. Which is often what is the main requirement. Unfortunately.
     
    PoPSiCLe, May 20, 2015 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,998
    Best Answers:
    253
    Trophy Points:
    515
    #12
    Yes, but for whom? the sleazy shit taking the scam arstist scumbag shortcuts shitting all over the Internet, or the poor ignorant site owner being outright scammed by this garbage?
     
    deathshadow, May 20, 2015 IP
  13. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #13
    Granted, a LOT of what you see created by Wordpress or similar is made by the site owner, or at least someone he knows or who works for him/her. Given the prices often quoted by webdevs in this country, I don't blame them. To build simple sites, say 15-20 pages, dynamic content, design etc. you're often looking at $5000-$10000 at least. That is INSANE, and clearly not something a lot of startups can afford.
     
    PoPSiCLe, May 20, 2015 IP