0
<div class="test" style="color:#fff; width:500px; height:100px;" on onmouseover="style='display:inline;'" onmouseout="<?php sleep(5) {//need a display none here}?>">

    <p>Hello All</p>

</div>

can some one help me please!!!

Edited by daniel.conlinjr.1

6
Contributors
10
Replies
40
Views
3 Years
Discussion Span
Last Post by JorgeM
Featured Replies
  • 2
    diafol 3,669   3 Years Ago

    Don't do it! PHP is not meant for this. You're looking for javascript functions. BTW, your html is a bit squiffy. <div class="test" style="color:#fff; width:500px; height:100px;" on onmouseover="style='display:inline;'" onmouseout="<?php sleep(5) {//need a display none here}?>"> <p>Hello All</p> </div> There's a orphaned 'on' going on in there. In addition, try to … Read More

0

I would never use PHP for this, have you considered using JS or is the use of PHP a must? Infact I don't think you'll ever achieve this with PHP alone.

Check out this example, it's pretty self explanatory and will show you how to hide/show a div using JS.

Good luck!
Michael

0

I would like to if possible to stick with php on most of it, but if I have to ill probably do a separate file and include it there.

0

You're still going to need to use JS though to show/hide the div without refreshing the page.

Only other choice is to refresh the page and use an if statement to hide or show the div.

0

I think you should listen to mmcdonald , some things like these are best solve with jquery and things like that...

0

PHP runs server-side, before rendering the output to the browser. Javascript runs client-side, in the browser. You cannot just add PHP code to a Javascript event like that.

0

PHP runs server-side, before rendering the output to the browser. Javascript runs client-side, in the browser. You cannot just add PHP code to a Javascript event like that.

Exactly my point, you either use JS Daniel or sit there for a few decades until PHP8 comes out, maybe that'll allow for similar functionality :D

0

Just to add.... there is not sleep() function in JavaScript. The closest would be setTimeout().

@daniel.conlinjr.1 - if you can provide more details as to exactly what you are trying to accomplish, you can be provided with better guidance.

Votes + Comments
+1
Wasnt using javascript was using a phpand html functions
2

Don't do it! PHP is not meant for this. You're looking for javascript functions. BTW, your html is a bit squiffy.

<div class="test" style="color:#fff; width:500px; height:100px;" on onmouseover="style='display:inline;'" onmouseout="<?php sleep(5) {//need a display none here}?>">
    <p>Hello All</p>
</div>

There's a orphaned 'on' going on in there. In addition, try to take out inline styling - this is never a good fix. Also, inline scripting should be taken out if possible and create 'listeners' instead. Keep your html lean.

<div class="test">
    <p>Hello All</p>
</div>

CSS file (or in style tags in head area)

.test{
    color:#fff; width:500px; height:100px;
}

JS file (or in script tags at bottom of page)

var divTest = document.getElementsByClassName('test');
divTest.addEventListener('mouseover', doSomething(), true);
divTest.addEventListener('mouseout', doSomethingElse(), true);

My vanilla js is shocking, so take the last bit with a pinch of salt.

Edited by diafol

0

@daniel.conlinjr.1-

Yes, I understand that you weren't trying to javascript. I was suggesting that you do.

Thanks for the feedback.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.