Jump to content

onclick display div - WONT DISPLAY


TeddyKiller

Recommended Posts

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>

Link to comment
Share on other sites

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>'; ?>

Link to comment
Share on other sites

... 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]

Link to comment
Share on other sites

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 />

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";
    }
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.