...

View Full Version : using php within javascript



bunny1
03-25-2007, 05:55 PM
I am trying to use php within this javascript

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




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;
}

the-dream
03-25-2007, 05:57 PM
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 '='!!

Inigoesdr
03-25-2007, 05:58 PM
You probably want "dept=", but what is the output/errors/desired output?

Nightfire
03-25-2007, 05:59 PM
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?

bunny1
03-25-2007, 06:12 PM
No even with those two things fixed it still doesnt pass the variables.it basically completely ignores the php

Inigoesdr
03-25-2007, 06:14 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum