#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2002
    Posts
    3
    Rep Power
    0

    javascript into php


    <script>

    c=document.forms[0].category.options[document.forms[0].category.selectedIndex].text
    <?php
    $x=c;
    ?>

    </script>

    but the php doesn't understand this c variable
  2. #2
  3. No Profile Picture
    newbie
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    Stockholm
    Posts
    8
    Rep Power
    0
    Im no javascript kiddie.. infact I hate it ;o)

    But anyways.. you will not be able to access javascript variables in a php script in the same page.
    You have to have this in mind:
    javascript is a "clientside" scripting language
    php is a "serverside" scripting language

    To get the vars from the javascript you will atleast have to make a page refresh or a post of some kind.

    cheers
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Bournemouth, England
    Posts
    28
    Rep Power
    0

    Unhappy javascript and php


    Hiya Rehab

    no javascript and php are not very good mates and you sometimes have to find a way round things.

    Any how, what exactly are you trying to do? Is the option selected for the user before the page is sent to the browser? If not you can't do anything on the same page with php after its been sent. All the php has finished running BEFORE its sent to the browser so u can't have an onSelect do stuff in php thang.

    If your php code is on the next page after posting just use the name of the form object as the variable and there's your value.

    If the problem is that you're losing multiple selections on post try this
    function reportMultiple()
    {/*Deals with multiple size selections - creates a ; seperated list*/
    var full_size_list = "";
    var the_select = document.form1.item_size2;
    for (counter=0; counter<the_select.options.length; counter++)
    {
    if (the_select.options[counter].selected == true)
    {
    full_size_list += the_select.options[counter].value + ";";
    }
    }
    document.form1.full_size_list.value = full_size_list;
    event.returnValue=true;
    }

    <form name="form1" onSubmit="reportMultiple();" method="post" action="editingItem.php" enctype="multipart/form-data">

    and on the 2nd page this

    $size_list = explode(';',$full_size_list);

    If I've not helped give me a bit more detail of exactly what your trying to achieve

    Mitchell

IMN logo majestic logo threadwatch logo seochat tools logo