Solved

IFrame URL variable (not being passed through javascript)

Posted on 2009-04-10
3
832 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
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 …

617 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