Solved

IFrame URL variable (not being passed through javascript)

Posted on 2009-04-10
3
822 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

756 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