Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript function and combined variables, help appreciated.

Status
Not open for further replies.

kigoobe

Programmer
Dec 25, 2007
6
FR
Well friends, I have just found this forum thro' google, so this is my first post.

I need to move the following code as a javascript function -

Code:
<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?>;
        subChoc('chocQnty_<?=$cid?>','totale_<?=$cid?>',<?=$cprix?>,chocArray,<?=$countNo?>,"",<?=$cid?>,ajaxArr);
    //-->      
    </script>
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 -

Code:
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 :)
 
On the PHP page, use something like this before you add the external JS file.
Code:
<script type="text/javascript">
var cid = '<?=$cid?>';
</script>

and

Code:
window['inter_' + cid] = document.getElementById('chocQnty_' + cid);

Lee
 
Hi, thanks. Actually, I could not declare any javascript variable in the main page. So, I solved this differently, thanks to locdev.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top