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 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts

    using php within javascript

    I am trying to use php within this javascript

    This code isnt working.How should i display the php code within javascript?


    PHP Code:
    function UpdateQty(item)
    {
    itemId = item.name;
    newQty = item.options[item.selectedIndex].text;

    document.location.href = 'cart.php?dept<?php echo urlencode($dept); ?>&type=<?php echo urlencode(type); ?>&action=update_item&id='+itemId+'&qty='+newQty;
    }

  • #2
    Regular Coder the-dream's Avatar
    Join Date
    Mar 2007
    Location
    Northamptonshire, UK
    Posts
    477
    Thanks
    8
    Thanked 4 Times in 4 Posts
    PHP Code:
    function UpdateQty(item) 

    itemId = item.name; 
    newQty = item.options[item.selectedIndex].text; 
     
    document.location.href = 'cart.php?dept=<?php echo urlencode($dept); ?>&type=<?php echo urlencode(type); ?>&action=update_item&id='+itemId+'&qty='+newQty; 
    }
    Dude U Forgot the '='!!

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You probably want "dept=", but what is the output/errors/desired output?

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Looks fine to me, apart from urlencode(type), that should be urlencode($type). Oh and also the missing = after dept

    When you view source, is the output of the php showing?

  • #5
    New Coder
    Join Date
    Feb 2007
    Posts
    92
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No even with those two things fixed it still doesnt pass the variables.it basically completely ignores the php

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    Is the file named .php? Unless the variables are empty you should be getting an error. Set error_reporting(E_ALL); at the top of the script.


  •  

    Posting Permissions

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