Ok...maybe not that hard.

I kinda understand that JS is client side and Php is server side...and in my googling i found a solution that many people suggest...I just cant seem to wrap my head around it...

you could also refresh the page with the variable in the url like:

url.php?scr_w_php=whatever

then access the variable:

echo $_REQUEST['scr_w_php'];

Thats what they all say...but what does it mean/how does it work?

For example. I have a javascript function that is trigged by an onclick:

<label id="<?php echo $dateCheck;?>" onclick="test(this.id)"><?php echo $dateCheck;?></label><br/>

so when it is clicked, the javascript function will have a parameter of...say...2009-05-03.

I want to set $Date to be THAT VALUE (the one passed in to javascript)

Right now just as a test I have:

<script type="text/javascript">

function test(date){

<?php
$query = "SELECT * FROM `pdem_timesheet`.`tblTimesheet`";
$result = mysql_query($query) or die("QUERY 1 ERROR");

$Date= mysql_result($result,0,"Date");
?>

document.write("<?PHP echo $FirstDay;?>");


}

</script>

like i said, purely a test to see if I can run a query once the JS function is called. (an i can, to my surprise 😛)

SO yeah. i need to do $Date = Date;...how do i do that...possibly using the code up above? (i need that explained 🙂 please) or ajax or what ever solution you have.

Thanks

    $GET (or if you prefer, $REQUEST) variables are queried from the string after the page name, which generally takes the form: "rootURL/page_name.php?var_name=value (optional: &var2name=value2 etc...)" - this may be clearer in the urlencode() manual page.

    In your example, change:

    <label id="<?php echo $dateCheck;?>" onclick="test(this.id)">

    To:

    <label id="<?php echo $dateCheck; ?>" onclick="document.location='this_page.php?value=' + this.id">

    When the page posts, you can query the "value" variable with: $GET['value'] or $REQUEST['value'], which will contain the value of "this.id" from the submitting page.

      It's client-side scripting, but in this case the client is posting the page. I try to avoid any URL variables except in cases where it won't matter, security-wise. For example, if I have a long list of company names that I want to display in alphabetical pages, I will use hyperlinks rather than a form drop-down (for example) for selecting a page index. So I'd have something like:

      <a href="this_page.php?page=a">a</a>
      <a href="this_page.php?page=b">b</a>
      <a href="this_page.php?page=c">c</a>
      <a href="this_page.php?page=d">d</a>

      I try not to use URL variables for anything that might trigger a query unless I do some heavy validation on the data.

        Write a Reply...