View Full Version : Javascript function and combined variables, help appreciated

12-25-2007, 01:27 PM
Well friends, I need some help, so here I am. I want to move the following code as a javascript function -

<script type="text/javascript">
var inter_<?=$cid?> = document.getElementById('chocQnty_<?=$cid?>');
if (inter_<?=$cid?> && inter_<?=$cid?>.value) {
var cqnty_<?=$cid?> = inter_<?=$cid?>.value;
} else {
var cqnty_<?=$cid?> = 0;
chocArray[<?=$countNo?>] = cqnty_<?=$cid?> + "~" + <?=$cprix?>;
ajaxArr[<?=$countNo?>] = <?=$cid?> + "~" + cqnty_<?=$cid?>;

As you can see, I need mixed / combined variables here, like inter_<?=$cid?> (I have used php here, since the javascript is a part of the main page, till now).

However, I want to move that to an external file, and tried doing something like -

function onloadEvents(cid,countNo,cprix) {
var inter_+cid = document.getElementById('chocQnty_'+cid);

It's not working. Wondering how can I get an equivalent of inter_<?=$cid?> in this function, where the value of $cid will come as a function argument.

Any help will be appreciated. Thanks. :)
Merry christmass to all :)

12-25-2007, 05:49 PM

Just wanted to inform that this is solved, thanks to locdev (http://forums.digitalpoint.com/showthread.php?t=617952).