Click here to Skip to main content
       

JavaScript

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page  Show 
QuestionJavascript/jquery problemmemberJohn Simmons / outlaw programmer21hrs 51mins ago 
I'm trying to load an image and retrieve its width/height. The image appears to be okay, but width/height are zero. The image isn't part of the page (yet), I'm simply creating it for later. Anyone got any help for me?
 
var id = this.FileName.replace(".png", "").replace(".jpg", "") + "_" + index;
var src = this.Path + this.Filename + "?" + new Date().getTime();
// create an image element, and set it up for use later on
this.ItemImage    = new Image();
$(this.ItemImage).attr(
{
    'src': src
    ,'id' : id
});
this.Width = $(this.ItemImage).width();
this.Height = $(this.ItemImage).height();
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

AnswerRe: Javascript/jquery problemprofessionalDennis E White21hrs 6mins ago 
John Simmons / outlaw programmer wrote:
The image isn't part of the page (yet), I'm simply creating it for later.

That is the answer to your problem.
 
since the image isn't loaded yet the browser won't set the width and height properties. will the image ever be loaded by the browser??
 
maybe try something like...
 
$('<img />').attr('src', 'http://urdomain.com/name.jpg').load(function(){
    if(true === this.complete) {
        var width = this.width;
        var height = this.height;
    } else {
        // unable to load image into memory
    }
});
as if the facebook, twitter and message boards weren't enough - blogged

GeneralRe: Javascript/jquery problemmemberJohn Simmons / outlaw programmer6hrs 43mins ago 
Your suggestion didn't work. I'm going to try adding a hidden div to the document, and then add images to that div. Maybe that will do what I need...
".45 ACP - because shooting twice is just silly" - JSOP, 2010
-----
You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass." - Dale Earnhardt, 1997

GeneralRe: Javascript/jquery problemprofessionalDennis E White3hrs 28mins ago 
John Simmons / outlaw programmer wrote:
Your suggestion didn't work

what part didn't work? did you get the callback from the load event?
as if the facebook, twitter and message boards weren't enough - blogged

QuestionHow to Add Days in Javascript Date ObjectmemberRobymon22 May '13 - 2:26 
I want to Add Number of Days with the Date object and get the New Date. i used this method to add Days
 
FromDate.setDate(FromDate.getDate() +12)
 
But this method is not working, if the month is February
 
EG: if the From Date is 20-02-2013, if i add 12 Days with this date, will get result as 01-03-2013.
 
Is there any other method to add days and check its leap year or not
AnswerRe: How to Add Days in Javascript Date ObjectprofessionalRichard Deeming22 May '13 - 3:23 
Are you sure you're looking at the correct month? In JavaScript, the Date object uses a zero-based month, so if getMonth returns 2, the date is in March.
 
var date = new Date(2012, 01, 20);
date.setDate(date.getDate() + 12);
alert(date); // Displays: "Sat Mar 03 2012 00:00:00 GMT+0000 (GMT Daylight Time)"



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer


AnswerRe: How to Add Days in Javascript Date ObjectprofessionalDennis E White22 May '13 - 4:39 
Can you give an example of your code that isn't working?? I tried the following and it all appears to be working just fine.
 
http://jsfiddle.net/SrVvn/[^]
as if the facebook, twitter and message boards weren't enough - blogged

AnswerRe: How to Add Days in Javascript Date ObjectmemberNiral Soni6hrs 14mins ago 
Hi Robymon,
 
The example you have given is incorrect.
 
Adding 12 days to 20-02-2013 will not give result as 01-03-2013, but will give 04-03-2013
 
The solutions given by "Richard Deeming" and "Dennis E White" are correct.
Thanks & Regards,
Niral Soni

Questionfunction for split a complex stringgroupmhd.sbt21 May '13 - 7:06 
hi to all
i have a string with this format
x=numbery=datez=number...
for example of this string can be :
x=123y=2013/02/01z=12345p=111
i want a function that get me this
x=123
y=2013/02/01
z=12345
p=111
 
how can i do this?
note to this point that my string can not be change and add extra character to this string
thanks in advance
AnswerRe: function for split a complex stringmemberryanb3121 May '13 - 10:30 
There is usually many ways to do string manipulation but one way would be to split on the = and then you'll have the rightmost character to be the starting of your next string. You'll have to put in a case for the first one.
 
Or, just loop through each character and process.
There are only 10 types of people in the world, those who understand binary and those who don't.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   


Advertise | Privacy | Mobile
Web04 | 2.6.130523.1 | Last Updated 23 May 2013
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid