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

Recommended Answers

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 …

Jump to Post

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.

Jump to Post

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

Jump to Post

All 10 Replies

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

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.

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.

I can do a sleep tho and then echo the display none can't I?

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

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.

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

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.

commented: Wasnt using javascript was using a phpand html functions +0
commented: +1 +11
Member Avatar

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.

@daniel.conlinjr.1-

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

Thanks for the feedback.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.