Passing parameters to IFRAME with multiple conditions

Posted on 2007-10-09
Last Modified: 2013-11-19

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">
    var 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){
    else { if(Variable_1 && Variable_3){


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.

Question by:musqo
    LVL 3

    Expert Comment

    check " search[text]= " ..

    Author Comment

    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.
    LVL 75

    Accepted Solution

    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 =;
    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"];

    LVL 75

    Expert Comment

    by:Michel Plungjan
    you MAY have to change



    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
    In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now