Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IFrame URL variable (not being passed through javascript)

Posted on 2009-04-10
3
Medium Priority
?
842 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 2000 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: 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

926 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