Solved

IFrame URL variable (not being passed through javascript)

Posted on 2009-04-10
3
820 Views
Last Modified: 2012-05-06
I have a piece of script that passes variables to an iframe.

But it seems it is only passing the first variable ( user_id ) and the others are being ignored.

It loads the user_id and then just ignores width, cid, ord etc

Any ideas why?
<!-- Get MINI SHOP-->
<script src="http://www.mydomain.com/jquery.js"></script>
<span id="205" class="user_id"></span>
<span id="900" class="height"></span>
<span id="900" class="width"></span>
<span id="0" class="cid"></span>
<span id="0" class="ord"></span>
<script src="http://www.mydomain.com/widget.js"></script>
<div id="shop"></div>
<!-- END MINI SHOP-->
 
 
 
 
 
 
JS Code that opens the iframe
 
// JavaScript Document
 
$(document).ready(function(){
 
	var user_id = $(".user_id").attr("id");
	var width = $(".width").attr("id");
	var cid = $(".cid").attr("id");
	var ord = $(".ord").attr("id");
	var qty = $(".qty").attr("id");
	var height = $(".height").attr("id");
		
 
 
	var htmlStr = '<iframe src=http://www.mydomain.com/mini_shop.php?user_id='+user_id+'&width='+width+'&cid='+cid+'&ord='+ord+'" scrolling="no" frameborder="0" height="'+height+'" width="'+width+'"></iframe>';
	
	$("#shop").html(htmlStr);
 
});

Open in new window

0
Comment
Question by:misi_uk
  • 2
3 Comments
 
LVL 9

Accepted Solution

by:
Mahdii7 earned 500 total points
ID: 24119972
A couple questions:

In the generated DOM source, are all the GET variables being passed to the iframe url? (src=http://www.mydomain.com/mini_shop.php?user_id=blah&width=blah&cid=blah&ord=blah)

If yes, what PHP are you using to parse the variables?
If no, there may be something wrong with your <input> fields or jQuery code (the jQuery looks OK though)

And, finally, as a sot in the dark, your HTML is invalid. Try this:
//CHANGE
	var htmlStr = '<iframe src=http://www.mydomain.com/mini_shop.php?user_id='+user_id+'&width='+width+'&cid='+cid+'&ord='+ord+'" scrolling="no" frameborder="0" height="'+height+'" width="'+width+'"></iframe>';
 
//TO
	var htmlStr = '<iframe src="http://www.mydomain.com/mini_shop.php?user_id='+user_id+'&width='+width+'&cid='+cid+'&ord='+ord+'" scrolling="no" frameborder="0" height="'+height+'" width="'+width+'"></iframe>';
 
// note missing double quote in src attribute

Open in new window

0
 

Author Comment

by:misi_uk
ID: 24120000
Let down but a silly missing " :)

Thank you its working great now!
0
 
LVL 9

Expert Comment

by:Mahdii7
ID: 24120144
Haha it happens. Glad I could help.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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