Skip to content Skip to sidebar Skip to footer

Transfer Data From Table

I have a table in HTML. JOHN DOEDOE TRUCKING<

Solution 1:

Here is the jsfiddle I don't know how you handle your popup but this is how your js should be structured.

$(function(){
    $('a').click(function(){
      $('h3').html($(this).html())
    });
});

Solution 2:

With the assumption that popup opens when you click on the <a> then you could just use $(this).text() and do something like this:

$(document).ready(function(){
    $('.name1 a').click(function() {
           $('.popup1 h3').text($(this).text());
        });
    });

Full example:

<table><tdclass="name1"><ahref="#">JOHN DOE</a></td><tdclass="company1">DOE TRUCKING</td><tdclass="position1">TRUCKER</td><tdclass="mc1">1234-567-8901</td><tdclass="dot1">1234-567-8901</td><tdclass="status1"><imgsrc="images/cross.png"width="12"height="12"alt="cross"></td></table><divclass="popup1"><divclass="cross3"><ahref="#"><imgsrc="images/closr-arrow.png"width="19"height="19"alt="closr-arrow"></a></div><h3>TABLE NAME</h3><ahref="#"class="approve">APPROVE ACCOUNT</a><ahref="#"class="deny">DENY ACCOUNT</a></div><script>
    $(document).ready(function(){
        $('.name1 a').click(function() {
            $('.popup1').lightbox_me({}); // <-- whatever your popup is, it plays no role here
            $('.popup1 h3').text($(this).text());
        });
    });
</script>

Sorry, you say lightbox but I cannot see how it's called or what lightbox given that lightbox is more of a gallery thing.

That's why I have used jQueryUI dialog instead, if this will not help then someone should take away your keyboard, and I hope this one will save you some duplication too (guessing given your class names).

<?php$rows=array(
    0=>array("id"=>'1',"name"=>'Tom',"company"=>'U',"status"=>'active'),
    1=>array("id"=>'2',"name"=>'Hre',"company"=>'E',"status"=>'suspended'),
    2=>array("id"=>'3',"name"=>'Peter',"company"=>'Pawtucket',"status"=>'wasted'),
    3=>array("id"=>'4',"name"=>'Griffin',"company"=>'Patriot',"status"=>'drunk'),
);

?><!DOCTYPE html><html><head><metahttp-equiv="content-type"content="text/html;charset=utf-8" /><scripttype="text/javascript"src="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script><linkhref="/jquery-ui-1.10.4/css/ui-lightness/jquery-ui-1.10.4.css"rel="stylesheet"><scripttype="text/javascript"src="/jquery-ui-1.10.4/js/jquery-ui-1.10.4.js"></script><style>.name {color:#00F;}
        </style><script>
        $(document).ready(function(){    
            $("#popup").dialog({
                autoOpen: false,
                modal: true,
                width: 500,
                height: 500,
                title: "Content From Row",
                closeOnEscape: true,
                closeText: "fechar",
                show: {
                    effect: "fadeIn",
                    duration: 1000
                },
                hide: {
                    effect: "fadeOut",
                    duration: 1000
                }
            });
        });
        </script><script>
            $(document).ready(function(){
                $('.name a').click(function() {
                    $('#popup h3').text($(this).text());
                    $(this).parent().siblings().each(function(){
                        if($(this).hasClass('company')){
                            $('#popup .popup_company').text($(this).text());
                        }
                        if($(this).hasClass('status')){
                            $('#popup .popup_status').text($(this).text());
                        }
                    });
                    $("#popup").dialog('open');
                });
            });
        </script></head><body><?phpif(is_array($rows)){
            ?><table><tr><td>Row No</td><td>ID</td><td>Name</td><td>Company</td><td>Status</td></tr><?phpforeach($rowsas$row_key=>$row){
                ?><tr><?phpif(is_array($row)){
                        echo('<td>'.$row_key.'</td>');
                        foreach($rowas$value_key=>$value){
                            if($value_key == "name"){
                                echo('<td class='.$value_key.'><a>'.$value.'</a></td>');
                            }else{
                                echo('<td class='.$value_key.'>'.$value.'</td>');
                            }
                        }
                    }
                ?></tr><?php
            }
            ?></table><?php
        }
        ?><divstyle="display:none;"><divid="popup"><divclass="cross3"><ahref="#"><imgsrc="images/closr-arrow.png"width="19"height="19"alt="closr-arrow"></a></div><h3>TABLE NAME</h3><ahref="#"class="popup_company"></a><ahref="#"class="popup_status"></a><ahref="#"class="approve">APPROVE ACCOUNT</a><ahref="#"class="deny">DENY ACCOUNT</a></div></div></body></html>

Post a Comment for "Transfer Data From Table"