Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to hide elements with Jquery if PHP variable is set
    text
    copied!<p>I've got this piece of script, and I'm trying to hide two divs (#black and #yname) if a certain variable or session is set in PHP, so is there a simple way to do so? Here's my code:</p> <p>input.php</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt; &lt;style type="text/css"&gt; @import "stil.css"; &lt;/style&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" src="jq.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="jquery-ui-1.8.13.custom.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="scripts.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="postme.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="wrap"&gt; &lt;div id="chat"&gt; &lt;div id="main"&gt; &lt;/div&gt; &lt;div id="input"&gt; &lt;form name="form"action="test.php" method="post"&gt; &lt;input type="text" name="tekst" id="msg" size="72" /&gt; &lt;input type="submit" name="dugme" value="posalji" id="dugme" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="black"&gt; &lt;/div&gt; &lt;div id="yname"&gt; &lt;form name="yname"&gt; &lt;input type="text" name="tekst2" /&gt; &lt;input type="button" name="dugme2" value="Enter" onclick="send()"/&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>postme.js</p> <pre><code>function send(){ $.post('sesion.php',{name:yname.tekst2.value},function(val){ } }); } </code></pre> <p>sesion.php</p> <pre><code>&lt;?php session_start(); $data=$_POST['name']; $_SESSION['name']=$data; $sesion_n=$_SESSION['name']; echo $sesion_n; ?&gt; </code></pre> <p>So basically, what I want to do is to check if $sesion_n variable is set, and if it's set, I want my send() function to hide divs #black and #yname.</p> <p>In addition, is there a way to use val value with jquery somehow for example to alert it or to assign that value to a javascript variable?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload