...

View Full Version : Problem with <div> id,javascript and two iframes



willlowonw
07-16-2010, 06:08 PM
Hello everyone,i will try to exaplain you what i am trying to do:

I am building a web site in html5 and right now i am working in drag n drop some images from one iframe to another.Until now everything worked great.Today i connected my first iframe with my database so all the pictures are taken from there.For this reason, in my code, i create several <div>,each one with id>=1.

My code for this is the following:



echo "<div class=\"drag\" id=\"".$info['id']."\" draggable=\"true\"><img src=\"postImages/".$info['id'].".jpg\" class=\"post\"></div>";

Its in php,but my results from chrome are the following:


<div class="drag" id="2" draggable="true"><img src="postImages/2.jpg" class="post"></div><<div class="drag" id="1" draggable="true"><img src="postImages/1.jpg" class="post"></div><div class="drag" id="3" draggable="true"><img src="postImages/3.jpg" class="post"></div><div class="drag" id="4" draggable="true"><img src="postImages/4.jpg" class="post"></div>

So,so far i created several <div>s with one class "drag" and different ids starting from 1 until 4.

And here start my problems!I have to change my code for the drag and drop functions in javascript in order to create a specific array with objects with id the <div> id.In more details,my code so far:


var people = {


Seth : {
blog : "http://google.com",
photo: "postImages/1.jpg"
}

Seth2 : {
blog : "http://google.com",
photo: "postImages/2.jpg"
}
};

What i want is the SECOND iframe to create an array named people,but insead of Seth and Seth2 the objects inside to have ids 1,2,3... from my <div>s from the previous iframe.

I am trying so many hours for this one (it is obvious that my javascript skills are not that good..) that i dont know what to do..i would be glad if you could help me!

Thanks in advance!

randomuser773
07-16-2010, 06:41 PM
IDs cannot begin with a digit, and neither can the names of variables, objects or their properties.

willlowonw
07-16-2010, 09:41 PM
This is indeed correct!I changed all the <div> ids and now they have one,two,three etc..Then i tried to grab the first one:


var object=document.getElementById('one').value;

and pass it as the first object in the array in the javascript:


var people = {
object : {
blog : "http://google.com",
photo: "postImages/1.jpg"
}
};

I still get the Uncaught TypeError: Cannot read property 'photo' of undefined when later i try to read the object.photo.In my opinion this means that the people array never existed..any more ideas?

edit:i put an alert after the first code,and it seems the object is unedtified..after this the page loads..is there any way the javascrript to runs before the html code?I have not include it as a seperate file,its in the end of the body...ah..so confused...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum