returning session variable with php / ajax

Discussion in 'PHP' started by red_fiesta, Aug 17, 2008.

  1. #1
    I have a page which has already done some ajax calls to php and has set some session variables.

    within my main page i need to now check these session varibles..

    if i was to use javascript the code could be something like

    <input id="question" type="text" name="question" maxlength="100" value="<?php echo "" ?>" style="width:590px" onkeydown="output()" />
    									
    								
    								<script language="javascript" type="text/javascript">
    								
    									function output() {
    									
    											
    											<?php
    											
    											if ( $_SESSION ["proselected"] == "yes" ) {
    											?>
    											
    											document.speakerForm.question.readOnly=false;
    											<?php
    											
    												}		 else {
    											?>
    											document.speakerForm.question.readOnly=true;
    											<?php
    											
    											
    												}
    											?>
    											
    											
    											
    											
    											//alert("hello");
    									
    									}
    								
    								</script>
    Code (markup):
    The problem with this obviously is that the session variable is always going to be set to no because when the main page loaded the proselected session variable had not been set.

    So, I need a way using ajax to check the state of the proselected session variable and if it is set to yes then the textfields readonly state can be set to false..

    thanks..
     
    red_fiesta, Aug 17, 2008 IP
  2. olaf2

    olaf2 Active Member

    Messages:
    1,362
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #2
    if you need the value from some session var you need to create a new server request
     
    olaf2, Aug 18, 2008 IP