Solved

IFrame URL variable (not being passed through javascript)

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
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.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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 …

707 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

18 Experts available now in Live!

Get 1:1 Help Now