Set a div to be a variable

How would I set the content of a div in an html file to be able to be called by a variable in a php file

ex: (Of what I would want to happen)

<div id="name">


<?php if($name == "") { echo "
Position Avaialable
"; } ?>


There is probably an easy solution, however, I don’t really understand the question.

I’m not sure if your checking if there IS a div, replacing it content, adding it dynamically??

Try and clarify the meaning of your question and I shall try and help you out. :wink:

I’m trying to be able to set up the contents within the div so that I can call on them as a variable.

So, referring to the code I first wrote I want to be able to say:

if name = blahblah do this. So I need to be able to give the div or text an id to call on in my php file.

Does that explain better?

Are you getting the content of the div dynamically from a var or database? If not you likely can’t do this with php. It would be very easy using jquery though.

php is server side, so by the time your page reaches the browser there is no php in the code any more and nothing more php can do from then on.

However, jQuery is your friend. :slight_smile:

HTML - Note the div ID.

<div id="myDiv">Hello World!</div>

Fetch using jquery calling on the ID like so:

$(document).ready(function() { var myDiv = $("#myDiv").text(); alert(myDiv); });

Hope that helps.

There is a way to do this without client-side scripting, but you’re better off with the suggestion above. But if you want to use just PHP, you would need to send the DIV information as form data, which you can send either to another page or to a reload of the current page, and then use PHP to do whatever with the form data. In some cases, that may be preferable to using Javascript, but it really depends on your specific situation.

Sponsor our Newsletter | Privacy Policy | Terms of Service