Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    May 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Variable Passing to function

    I have a program using java that passes two variables to the UpdateItem function but do not know how to add another variable. The java recalculates the quantity and passes this along with the unchanged itemId back to the function UpdateItem. I started adding a third item called install and would like to pass it unchanged to the UpdateItem function but could not get it to work, your assistance would be appreciated

    function UpdateQty(item)
    {
    itemId=item.name;
    install=item.install;
    newQty=item.options[item.selectedIndex].text;
    document.location.href='cart.php?action=update_item&id='+itemId+'&qty='+newQty;
    }

    function UpdateItem($itemid, $qty, $install)
    {global $dbServer, $dbUser, $dbPass, $dbName;
    // Get a connection to the database


    <select name="<?php echo $row["itemId"]; ?>", install="<?php echo $row["install"]; ?>" onchange="UpdateQty(this)">
    <?php

    for($i = 1; $i <= 20; $i++)
    {echo "<option ";
    if($row["quant"] == $i)
    {echo " SELECTED ";}
    echo ">" . $i . "</option>";}?>
    </select>
    $cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);



    Thanks
    mitch

  • #2
    New Coder
    Join Date
    Apr 2007
    Location
    Silicon Valley California
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yikes....

    First, there is no Java code anywhere in your example. There is JavaScript and PHP code, both are very different from Java.

    Second, your UpdateItem function is written in PHP, not in JavaScript.

    Please restate your question to address these issues. I'm not sure what you are asking.

  • #3
    New Coder
    Join Date
    May 2007
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I would like to pass a another variable 'install' from the HTML select name through the javascript to the PHP function UpdateItem. Presently the variable 'itemId' is passed unchanged this way and 'qty' is updated for the PHP function.

    Hope this helps

  • #4
    New Coder
    Join Date
    Apr 2007
    Location
    Silicon Valley California
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Mitch, you can't pass variables from JavaScript to PHP. That is impossible.


  •  

    Posting Permissions

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