TeddyKiller Posted May 2, 2010 Share Posted May 2, 2010 I'm wanting to display a div when onclick textbox. Although nothing gets displayed? Cant see the problem. Any help? Thanks! <script language="JavaScript"> function showPalette(Click_Menu) { if (Click_Menu.style.display == "none") { Click_Menu.style.display = ""; } else { Click_Menu.style.display = "none"; } } </script> <div id="palette" style="display:none"> <table bgcolor="#FFFFCC"> <tr> <td width="200" wrap>COLOUR PALETTE</td> </tr> </table> </div> <form action=""> <input type="text" name="status" size="40" onclick="showPalette('palette')"/> </form> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 It works now, but not when its actually put to the test on my site. It has to be in an an echo. So I have this.. and it doesn't work. <script type="text/javascript"> function showPalette(Click_Menu) { if (Click_Menu.style.display == "none") { Click_Menu.style.display = ""; } else { Click_Menu.style.display = "none"; } } </script> <?php echo '<div id="editstatus" style="text-align:left;"> <div id="palette" style="display:none"> <table bgcolor="#FFFFCC"> <tr> <td width="200">COLOUR PALETTE</td> </tr> </table> </div> <form action="" method="post"> <input type="text" name="status" size="40" value="' . bbcode_format($msta['status'], 2) . '" onclick="showPalette(palette)" /> <input type="submit" name="submitstatus" value="submit"/> <a href="#" onclick="showPane(\'status\')">cancel</a> </form> </div>'; ?> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 ... I tested that code, and it works.. The whole echo works too.. (in a clean file) for some reason.. Just not in the file. I'll probably be needing someone to take a look at the whole code.. 390 lines in total. I can't seem to fine the problem. It's PHP so.. if you don't know it, I recommend don't download the file. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 I just took a glance and didn't bother reading all of it. But what exactly is not working. Because that really doesn't make sense. Does it do nothing or something undesired? Quote Link to comment Share on other sites More sharing options...
Zane Posted May 2, 2010 Share Posted May 2, 2010 you have to tell Javascript what element object your working with. Even though you're passing the id "pallete".. it doesn't mean it's automatically a reference. <br /> function showPalette(Click_Menu) {<br /> Click_Menu = getElementById(Click_Menu);<br /> if (Click_Menu.style.display == "none") {<br /> Click_Menu.style.display = "";<br /> } else {<br /> Click_Menu.style.display = "none";<br /> }<br /> }<br /> Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 It works without that in a clean file, so something must be attacking it. I put it in, and it didn't work. I changed it so that it was Click_Menu = document.getElementById(Click_Menu); As I thought this would make more sense. This also didn't work. The div to be shown is on line 129. Or alternatively you can do a search for "COLOUR PALETTE" Nothing happens. I click the textbox, and nothing gets displayed. It should get displayed above the textbox.. but it doesn't show up anywhere. If I copy and paste that whole echo.. into a clean file, with the javascript, it works fine.. it does what I expect it to do. So somethings stopping it from working, but I don't know what? Quote Link to comment Share on other sites More sharing options...
Zane Posted May 2, 2010 Share Posted May 2, 2010 It's because in order to display something... the display value has to be something.. like "block" or "inline" Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 function showPalette(Click_Menu) { Click_Menu = document.getElementById(Click_Menu); if (Click_Menu.style.display == "none") { Click_Menu.style.display = "block"; } else { Click_Menu.style.display = "none"; } } </script> This doesn't work still.. the problem isn't the javascript, or part the form.. because in a seperate file, that works fine. http://horble.com/design/tester.php You can test it there. It's the exact same code. Except the divs etc are echo'd out but in the source code you can see that it is effectively the same thing. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Add single quotes to onclick="showPalette('palette')" Also, add a check. function showPalette(Click_Menu) { Click_Menu = document.getElementById(Click_Menu); if (!Click_Menu || !Click_Menu.style) return; if (Click_Menu.style.display == "none") { Click_Menu.style.display = "block"; } else { Click_Menu.style.display = "none"; } } Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 Ahh, that works! Thanks. Can you explain why within the main page, it wouldn't work.. yet in a clean file.. with just the divs, and javascript, and a style it works? Something must of got in the way? You wouldn't know how to add in squares of colours of my choice, in the colour palet div. Like a colour picker. When one is clicked (onClick event maybe) it'll insert certain text into the textbox. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Code behaves differently when it's incorrectly written. The fact it works doesn't mean it's correct. So no, I don't know. As for the color palette, I'm sure you can add more to it. I haven't looked through your mess to say how though. Post up the relevant bits. Quote Link to comment Share on other sites More sharing options...
Zane Posted May 2, 2010 Share Posted May 2, 2010 You wouldn't know how to add in squares of colours of my choice, in the colour palet div. Like a colour picker. This is when the table tag (and all its descendants) comes in handy Quote Link to comment Share on other sites More sharing options...
TeddyKiller Posted May 2, 2010 Author Share Posted May 2, 2010 You wouldn't know how to add in squares of colours of my choice, in the colour palet div. Like a colour picker. This is when the table tag (and all its descendants) comes in handy Ahhh shhh yeah. Didn't think of that. Can you have td onclicks? so I can call a function.. via clicking the td space. If it was possible for that, I'd have the onclick function as "colorpicker('#fff000')" then the function would process the colour.. and output a result in the textbox. (Doesn't change it, it just puts it in) Then.. if I highlighted some text, and clicked a colour. how would I wrap that text with the colour tags? Really puzzled. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2010 Share Posted May 2, 2010 Ever Googled? http://www.w3schools.com/TAGS/tag_td.asp Looks like it does. lol 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.