Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Passing parameters to IFRAME with multiple conditions

Posted on 2007-10-09
6
Medium Priority
?
7,643 Views
Last Modified: 2013-11-19
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
0
Comment
Question by:musqo
5 Comments
 
LVL 3

Expert Comment

by:rlbalan
ID: 20045270
check " search[text]= " ..
0
 

Author Comment

by:musqo
ID: 20045395
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.
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 20047021
Here is a vastly simplified version

<iframe name="Shop" id="Shop" width="100%" height="1875" src="blank.htm"></iframe>

<script type="text/javascript">
var search = location.search;
var url = "blank.htm";
if(search) {
  search = search.substring(1);
  var parms = new Array()
  var searchAttributes = search.split('&');
  for(var i=0;i<searchAttributes.length;i++){
    var items = searchAttributes[i].split('=');
    parms[items[0]] = items[1];
  }
  url ='shop.php?sid='var_1='+parms["Variable_1"];
  if (parms["Variable_3"]) url+='&search[text]='+parms["Variable_3"]
  else url+='&var_2='+parms["Variable_2"];
}
document.getElementById('Shop').src=url;

</script>
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20047026
you MAY have to change
'&search[text]='

to

'&search%5Btext%5D='

 
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20561838
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question