Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Problem with <div> id,javascript and two iframes

    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:


    Code:
    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:

    Code:
    <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:

    Code:
    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!

  • #2
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    IDs cannot begin with a digit, and neither can the names of variables, objects or their properties.

  • Users who have thanked randomuser773 for this post:

    willlowonw (07-16-2010)

  • #3
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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:

    Code:
    var object=document.getElementById('one').value;
    and pass it as the first object in the array in the javascript:

    Code:
    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...
    Last edited by willlowonw; 07-16-2010 at 10:02 PM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •