ckrudelux Posted March 3, 2010 Share Posted March 3, 2010 If I take the alert away it just skip the loop and continues. Have no clue way maybe I missed something but nothing I can see. <?php include "../dbconnect.php"; function managegroups($table, $type, $object_id){ $id = md5($table.$type.$object_id.rand(0000,9999)); echo "<div id=\"".$id."\">"; echo "<div class=\"items\">"; $select = mysql_query("SELECT * FROM groups"); while($row = mysql_fetch_assoc($select)){ ?> <div onclick="addgroup('<?php echo $id;?>', '<?php echo $row['g_id'];?>', '<?php echo $row['name'];?>');" class="item1"><?php echo $row['name']?></div> <?php } echo "</div>"; echo "<div class=\"selecteditems\">"; $select = mysql_query("SELECT * FROM $table WHERE type='$type' and object_id='$object_id'"); while($row = mysql_fetch_assoc($select)){ $g_id = $row['g_id']; $select2 = mysql_query("SELECT * FROM groups WHERE g_id='$g_id'"); while($row2 = mysql_fetch_assoc($select2)){ ?> <div class="item1"> <?php echo $row2['name']?> <input type="hidden" class="hello" value="<?php echo $g_id?>" /> </div> <?php } } echo "</div>"; echo "</div>"; }?><!DOCTYPE html> <head> <style type="text/css"> .item1 { float: left; margin: 5px; padding: 5px; width: 110px; text-align: center; cursor: pointer; border: 1px solid #000; background: #888; } .items { float: left; width: 150px; height: 100px; overflow: auto; border: 1px solid #000; } .selecteditems { float: left; margin-left: 10px; width: 420px; height: 100px; overflow: auto; border: 1px solid; } </style> <script type="text/javascript"> function addgroup(objectid, objectgid, objectname){ var main = document.getElementById(objectid); var allDivs = main.getElementsByTagName('div'); var i = 0; for(i=0; i < allDivs.length; i++){ if(allDivs[i].className == "selecteditems"){ var state = false; var cl = 0; var listallDivs = allDivs[i].getElementsByTagName('div'); alert("start"); //OK for(cl=0; cl < listallDivs.length; cl++){ alert("loop"); //OK var li = 0; var myinputs = listallDivs[cl].getElementsByTagName('input'); alert(myinputs.length); // 1 OK //alert(myinput[0].value); //Stops script HERE! for(li=0; li < myinputs.lenght; li++){ alert(myinput[li].value); if(myinput[li].value == objectgid){ state = true; } } } alert("end"); if(state == false){ allDivs[i].innerHTML += "<div class=\"item1\">"+objectname+"<input type=\"hidden\" value=\""+objectgid+"\" /></div>"; } } } } </script> </head> <body> <?php managegroups("paragraph_groups", "1", "84"); ?> </body></html> Link to comment Share on other sites More sharing options...
Synook Posted March 3, 2010 Share Posted March 3, 2010 Well, you seem to have gotten confused as to whether your variable is called myinputs or myinput: var myinputs = listallDivs[cl].getElementsByTagName('input');alert(myinputs.length); // 1 OK//alert(myinput[0].value); //Stops script HERE! Also, you've spelled "length" wrong here: for(li=0; li < myinputs.lenght; li++){ Link to comment Share on other sites More sharing options...
ckrudelux Posted March 3, 2010 Author Share Posted March 3, 2010 Well, you seem to have gotten confused as to whether your variable is called myinputs or myinput:var myinputs = listallDivs[cl].getElementsByTagName('input');alert(myinputs.length); // 1 OK//alert(myinput[0].value); //Stops script HERE! Also, you've spelled "length" wrong here: for(li=0; li < myinputs.lenght; li++){ Ow! didn't see what btw I need a code for delete a div and all I can find is removeChild but I want to use this.remove or something like what. Link to comment Share on other sites More sharing options...
Synook Posted March 3, 2010 Share Posted March 3, 2010 removeChild is the right way, unless you want to modify the innerHTML of the parent. Is there any specific reason why you need the function to be a member of the to-be-removed division? You can get an element's parent using the parentNode property. Link to comment Share on other sites More sharing options...
ckrudelux Posted March 3, 2010 Author Share Posted March 3, 2010 removeChild is the right way, unless you want to modify the innerHTML of the parent. Is there any specific reason why you need the function to be a member of the to-be-removed division? You can get an element's parent using the parentNode property.Well I want to remove my button.. <div onclick="deletegroup(this);">Button</div> Link to comment Share on other sites More sharing options...
Synook Posted March 3, 2010 Share Posted March 3, 2010 element.parentNode.removeChild(element); Link to comment Share on other sites More sharing options...
ckrudelux Posted March 3, 2010 Author Share Posted March 3, 2010 element.parentNode.removeChild(element); Thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.