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.l ength;no++ ){
var items = searchAttributes[no].split ('=');
eval("var "+items[0]+" = '"+items[1]+"';");
}
if(Variable_1 && Variable_2){
document.getElementById('S hop').src= 'shop.php? var_1='+Va riable_1+' &var_2='+V ariable_2;
}
else { if(Variable_1 && Variable_3){
document.getElementById('S hop').src= 'shop.php? sid='var_1 ='+Variabl e_1+'&sear ch[text]=' +Variable_ 3;
};}
}else{
document.getElementById('S hop').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
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>
var search = location.search;
search = search.replace(/\?/,'');
var searchAttributes = search.split('&');
for(var no=0;no<searchAttributes.l
var items = searchAttributes[no].split
eval("var "+items[0]+" = '"+items[1]+"';");
}
if(Variable_1 && Variable_2){
document.getElementById('S
}
else { if(Variable_1 && Variable_3){
document.getElementById('S
};}
}else{
document.getElementById('S
}
</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
check " search[text]= " ..
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you MAY have to change
'&search[text]='
to
'&search%5Btext%5D='
'&search[text]='
to
'&search%5Btext%5D='
Forced accept.
Computer101
EE Admin
Computer101
EE Admin