Link to home
Start Free TrialLog in
Avatar of musqo
musqo

asked on

Passing parameters to IFRAME with multiple conditions

Hi,

I am a novice at this and I got this code online and tweaked it a little. But it doesn't work. I am trying to pass 2 of 3 possible variables to an inline frame. Var_1 is always passed through, and either var_2 or var_3. The following is a sample of the code I am currently using; i have changed the variable names to make it easier to follow.

<iframe name="Shop" id="Shop" width="100%" height="1875" src="shop.php?"></iframe>
<script type="text/javascript">
if(location.search.length>0){
    var search = location.search;
    search = search.replace(/\?/,'');
   
    var searchAttributes = search.split('&');
    for(var no=0;no<searchAttributes.length;no++){
        var items = searchAttributes[no].split('=');
        eval("var "+items[0]+" = '"+items[1]+"';");
    }
    if(Variable_1 && Variable_2){
        document.getElementById('Shop').src='shop.php?var_1='+Variable_1+'&var_2='+Variable_2;
                 }
    else { if(Variable_1 && Variable_3){
        document.getElementById('Shop').src='shop.php?sid='var_1='+Variable_1+'&search[text]='+Variable_3;
                 };}
}else{
    document.getElementById('Shop').src='blank.htm';

}
</script>

It appears that I a able to pass Variable_1 and Variable_2 into the inline frame without a problem. However, in cases where Variable_3 is used the variable is not passed through...and the inline frame only lands at shop.php?. I think it is something to do with the if else statement, but I looked it over a thousand times and I can't seem to figure it out. Can anyone help be figure out what's wrong with this code? Any help would be much appreciated.

Thanks
Avatar of rlbalan
rlbalan

check " search[text]= " ..
Avatar of musqo

ASKER

i am not sure I understand what you mean...but I switched search[text] and var_2 and search[text] seems to work fine if it is the first condition. The script appears to stop executing after calculating the first condition.
ASKER CERTIFIED SOLUTION
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you MAY have to change
'&search[text]='

to

'&search%5Btext%5D='

 
Forced accept.

Computer101
EE Admin