F1Fan Posted September 29, 2008 Share Posted September 29, 2008 I have a file library program that I'm having issues with. Some people have view access, others have edit access. Everyone can click on a file to open it, while those with edit access can click on the main image to open it, or they can click a little "X" image to delete it. The X image has a z-index of 2 so it displays on top of the main image. My problem is that if someone clicks the X image to delete it, it will run the deleteLibFile JS function AND the openFile JS function. So, this is my question: how can I stop the openFile function from running if the X was clicked? I tried adding a global variable that openFile checks for. When deleteLibFile is run, the variable is set and openFile will not run. There are two problems with that: 1) If I reset the variable if they click cancel, when they click cancel, it will then run openFile. 2) If I don't reset the variable when they click cancel, then if they try to open the file, that var is still set and openFile won't run. There's a lot more to it than this, but here's the important stuff: PHP: <?php foreach ($lib->getContents($empnum) as $f){ if ($f['type']=="file") $onclick = "openFile('{$f['file']}',0);"; else $onclick = "openDir('{$f['file']}',0);"; ?> <div class="filediv" onclick="<?php echo $onclick; ?>" id="<?php echo $f['id']; ?>" onmouseover="mouseOverTDs('<?php echo $f['id']; ?>');" onmousedown="return nd();" onmouseout="mouseOutTDs('<?php echo $f['id']; ?>');"> <table class="filetable" id="table<?php echo $f['id']; ?>"> <tr> <td class="tdimage" id="1td<?php echo $f['id']; ?>"> <div class="divimage"> <div class="lockover<?php echo ($f['view_access']?"off":"on"); ?>"> <image src="images/library/lock.png" title="You do not have access to this <?php echo $f['type']; ?>"> </div> <div class="xover<?php echo ($f['edit_access']?"on":"off"); ?>" onclick="deleteLibFile('<?php echo "{$f['id']}','{$f['type']}','{$f['file']}','".$lib->curdir; ?>');"> <image onclick="<?php echo $onclick; ?>" src="images/library/no.png" title="Delete <?php echo $f['type']." '".$f['file']; ?>'"> </div> <image src="images/library/<?php echo $f['image']; ?>"> </div> </td> </tr> <tr> <td id="2td<?php echo $f['id']; ?>"> <div class="tdfile" <?php echo $f['trim_file']==$f['file']?"":"title=\"{$f['file']}\""; ?>> <?php echo $f['trim_file'].($f['type']=="directory"?"/":""); ?> </div> </td> </tr> <tr> <td id="3td<?php echo $f['id']; ?>"> <div class="tdtitle" <?php echo $f['trim_title']==$f['title']?"":"title=\"{$f['title']}\""; ?>> <?php echo $f['trim_title']; ?> </div> </td> </tr> </table> </div> <?php } ?> CSS: .xoveron{ display: block; position: absolute; top: 0px; right: 43px; z-index: 2; } .xoveroff{ display: none; } and JS: var stop = false; function deleteLibFile(id,type,file,curdir){ stop = true; if (confirm("Are you sure you want to delete "+type+" \""+file+"\"?")){ window.location = 'main.php?c[f]=library&c[a]=main&curdir='+curdir+'&delfile='+id; } //stop = false; } function openFile(file,count){ if (count==5){ if (!stop){ window.open('features/library/files/'+file); } } else{ count++; setTimeout("openFile('"+file+"',"+count+")",10); } } Any help will be appreciated. Quote Link to comment Share on other sites More sharing options...
F1Fan Posted September 29, 2008 Author Share Posted September 29, 2008 Never mind, I figured it out. Just added a little more JS. Here was my solution, it anyone cares: var stop = false; function deleteLibFile(id,type,file,curdir){ stop = true; if (confirm("Are you sure you want to delete "+type+" \""+file+"\"?")){ window.location = 'main.php?c[f]=library&c[a]=main&curdir='+curdir+'&delfile='+id; } setTimeout("resetStop()",100) } function resetStop(){ stop = false; } function openFile(file,count){ if (count==5){ if (!stop){ window.open('features/library/files/'+file); } } else{ count++; setTimeout("openFile('"+file+"',"+count+")",10); } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.