0

this my code with in a array i supposed to make tree menu in a table

$myqueryPO->magGrp = array("[grp] => MAIN, [grp] => P1,  [grp] => P3")
foreach ( $myqueryPO->magGrp as $dataArray) {
$myGroup = $dataArray[] = $dataArray['grp'];
    <tr class="'.$myGroup.'">
        <td><a href="#" id="'.$myGroup.'" class="clickMEdata">'.$myGroup.'</a></td>
        <td></td>
    </tr>

}


$(function($) {
$(".clickMEdata").click(function(){
var eleMent = $(this);
var mySelected = eleMent.attr("id");
var info = "myID=" + mySelected;
$.ajax({
type: "POST",
url: "ScheduleOfManPower.php",
data: info,
success: function(data){    
var loadUrl = "ScheduleOfManPower.php";
 $("."+mySelected).append().load(loadUrl, info);
}
});
$("."+mySelected).toggle("slow");
});
}); 

supposed to be the ScheduleOfManPower.php is <tr><td>hi</td><td>foo</td></tr> my problem it seem my append function doesnt work my table not fit what i expected its only query in the 1st <td></td> my second problem is the $("."+mySelected).toggle("slow"); it seem i need to double click in order from me to show my query.. :(

1
  • Is this the actual code you use? Because some things are really wrong. Commented Aug 1, 2010 at 11:10

2 Answers 2

1

I'm not sure from the question what's supposed to be going on, but you have a few issues off the bat. $("."+mySelected) is a .class selector, not an ID selector. You'll want this to search by ID:

 $("#"+mySelected)

But there's no need for that, just keep a reference, like this:

$(function($) {
  $(".clickMEdata").click(function(){
    var eleMent = $(this);
    $.ajax({
      type: "POST",
      url: "ScheduleOfManPower.php",
      data: { myID: eleMent.attr("id") },
      success: function(data){
        eleMent.closest('tr').after(data);
      }
    });
    eleMent.toggle("slow");
  });
});

This has a few other changes/fixes, you can pass data as an object making that cleaner. If you want to append the returned data you need to use data in your success function, calling .load() will fire another different AJAX request, which doesn't make much sense, but given you're loading it both ways, I'm not sure exactly what you're after...but I think the above is it.

There's one more big change, you were appending a <tr> inside an <a> which isn't valid at all, I changed it to insert it as the next row. This one I'm really unsure of, but it's the only thing close that's valid HTML, so please elaborate if it's not what you were after.

Sign up to request clarification or add additional context in comments.

4 Comments

tnx nick this code is perfect but another problem is the eleMent when i excuted it will hide the eleMent and when i disable the eleMent.toggle("slow"); it will duplicate the data onlick..
@mapet - Can you be a bit more specific? I'm now following you from the description...
sorry ^^ when i onlick the "#clickMEdata" it will excute eleMent.toggle("slow"); but it will hide the var eleMent = $(this);.. and my other problem is when i double click the eleMent = $(this) is will duplicate the query..
i try the this function before eleMent.toggle( function () { //1st click show the data eleMent.closest("tr").after(data); }, function () { }); //2nd click hide the data $("."+mySelected).hide(); } }); but this code doesn't work for me
0

i get it ^^ .. thank u nick

$(function($) {
$(".clickMEdata").toggle(
function(){
var eleMent = $(this);
var mySelected = eleMent.attr("id");
var myHuraFrom = eleMent.attr("huraUna");
var myHuraTO = eleMent.attr("huraTwo");
var info = "myID=" + mySelected+ "&MaHuraFrom="+myHuraFrom+ "&myHuraTO="+myHuraTO;
$.ajax({
type: "POST",
url: "ScheduleOfManPower.php",
data: info,
success: function(data){        
eleMent.closest("tr").after(data);
}
});                                     
},
function (){
$(".activity").hide();  
});
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.