SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JavaScript calling a PHP variable

    I wonder if it is possible for JavaScript to call a PHP variable.

    for example on what I am working on:

    <?
    function test()
    {

    ?>
    <SCRIPT LANGUAGE="JavaScript">
    function abc()
    {
    var RadioValue;
    if(document.test.number.value == 10)
    time=15;
    else if(document.test.number.value == 20)
    time=30;
    else(document.test.number.value == 30)
    time=45;
    }
    url = "http://www.certifyexpress.com/exam/oracle/indexR.php?time="+$time+"&action=quiz&number="+document.test.number.value+"&quiz="+RadioValue+"&name="+test.name.value+"&email="+test.email.value;

    </script>

    <?
    function timing()
    {
    global $time;
    global $hhh;
    ?>
    <SCRIPT LANGUAGE="JavaScript">
    <!--

    if ($time = document.test.number.value){
    if(document.test.number.value == 10)
    $time = 15;

    else if(document.test.number.value == 20)
    $time = 30;

    else
    $time = 45;

    }
    ?>

    thanks.. new to Jscript...

  2. #2
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    time="+$time+"&action=quiz&number="+document.test.number.value+"&quiz="+RadioValue+"&name="+test.name.value+"&email="+test.email.value;
    I assume you are talking about that line. If you have a variable in php you want transferred to javascript simply do an echo of the variable. Just remember that php is parsed out so this is an example

    Code:
    var time=<?= $time; ?>
    That would make time in javascript equal to whatever variable you have defined in php called time.
    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  3. #3
    SitePoint Member
    Join Date
    Nov 2001
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <SCRIPT LANGUAGE="JavaScript">
    <!--


    <? if($time=document.test.number.value) {
    if(document.test.number.value == 10)
    $time = 15;
    else if(document.test.number.value == 20)
    $time=30;
    else
    $time=45;
    }
    ?>
    $time is a php variable.. while the rest is JavaScript. I wan the $time = document.test.number.value

    p/s: I did some changes, and my timer works. just that it doesn't run the specific time for the specific number of questions.




    pls Help!!!!
    Last edited by diskette; Nov 30, 2001 at 03:50.


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
  •