0

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:

input.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
@import "stil.css";
</style>
<title>Untitled Document</title>
<script type="text/javascript" src="jq.js"></script>
<script type="text/javascript" src="jquery-ui-1.8.13.custom.min.js"></script>
<script type="text/javascript" src="scripts.js"></script>
<script type="text/javascript" src="postme.js"></script>
</head>
<body>
<div id="wrap">
<div id="chat">
<div id="main">
</div>
<div id="input">
<form name="form"action="test.php" method="post">
<input type="text" name="tekst" id="msg" size="72" />
<input type="submit" name="dugme" value="posalji" id="dugme" />
</form>
</div>
</div>
</div>
<div id="black">
</div>
<div id="yname">
<form name="yname">
<input type="text" name="tekst2" />
<input type="button" name="dugme2" value="Enter" onclick="send()"/> 
</div>


</body>
</html>

postme.js

function send(){
$.post('sesion.php',{name:yname.tekst2.value},function(val){

    }
});
}

sesion.php

<?php
session_start();
$data=$_POST['name'];
$_SESSION['name']=$data;
$sesion_n=$_SESSION['name'];
echo $sesion_n;
?>

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.

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?

4
  • 1
    Out of curiosity, are you using the spelling 'sesion' because that's how it's spelled in a language other than English? I see things like this all the time, and I'm wondering why it happens, when you can spell the global $_SESSION correctly. Commented Jun 17, 2011 at 11:03
  • Your $sesion_n variable will always be set because you're setting it in the request. Commented Jun 17, 2011 at 11:46
  • @ Frank Crook It's rather simple, I'm not a native English speaker, therefore I'm not that good at spelling, so I can easily misspell something, so I'm trying to keep my variables similar to my native language Commented Jun 18, 2011 at 6:58
  • @Jivings I guess, so but is there a way for me to check and display the exact value of that variable? Commented Jun 18, 2011 at 8:11

2 Answers 2

1
function send(){
   $.post('sesion.php',{name:yname.tekst2.value},function(val){
            if(val) {
                $('#black').hide();
                $('#yname').hide();  
            }

        }
   });
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, I tried it but nothing happens when I click my button.
Is it sending the POST request? You can check using firebug or Chrome development window.
It seems that POST request isn't sent, the Chrome development window gives me this message: Uncaught TypeError: Cannot read property 'value' of undefined sendpostme.js:2 (anonymous function)input.php:32 onclick
I've found a solution, apparently the problem was that my form had a name yname and the parent div had the yname as the id, so that was the problem, and after changing div's id to name everything works as a charm. Anyway, your answer was most helpful, so I'll accept it, thank you.
0

well i didnt get your question completely but you can use hide() method to hide any div in jquery...

1 Comment

I want to hide the elements if val variable is set(preferably it has a certain value), and in addition, I was wondering is there a way to use the val variable with Javascript to alert it or use it in a equation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.