SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: function help

  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function help

    hi!
    i wonder if anyone knows why that function wont work?
    hth
    Code:
    <script type="text/javascript" language="javascript">
    function modmath(numt) {
    <?php
    $ret = mysql_query("SELECT * FROM mathop WHERE id = '?>numt;<?php'");
    while($row = mysql_fetch_row($ret)) {
    ?>
    x = (document.getElementById("valz").value * 1)<?php switch ($row[2]) { case "+":echo "+".$row[3];break;case "-":echo"-".$row[3];break;case "x":echo "*".$row[3];break;case "/":echo "/".$row[3];break;case ("+%") || ("-%"):echo "/100*".$row[3];break; }?>;
    <?php 
    switch ($row[2]) {
    case ("+") || ("-") || ("x") || ("/"):
    echo "document.getElementById(\"valz\").value = x;";
    break;
    case "+%":
    echo "y = (document.getElementById(\"valz\").value * 1) + x;";
    echo "document.getElementById(\"valz\").value = y;";
    break;
    case "-%":
    echo "y = (document.getElementById(\"valz\").value * 1) - x;";
    echo "document.getElementById(\"valz\").value = y;";
    break;
    }
    }
    ?>
    }
    </script>
    maybe couse php need a refresh page to get the where id = $variable?
    any suggestion?
    thanx in advance!!!

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Quote Originally Posted by reminder
    maybe couse php need a refresh page to get the where id = $variable?
    Yes, the page has to be reloaded if you want PHP to access the value. PHP is executed on the server, and the Javascript is executed on the client (when the Javascript is executed, the execution of PHP has ended).

    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do u have any suggestion like how to resolve this function problem?
    thanx


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •