im looking for this Ajax Script

medina

x10 Addict
Community Support
Messages
1,811
Reaction score
7
Points
38
I am looking for script in AJAX who changes the dimensions of a DIV.

im try to find it in google but nothing... please help me!
 

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
There is nothing Ajax-y about resizing an element. Ajax, by definition, means making a background request to the server. All you need is plain old JavaScript.

Code:
function resizeElement(div, height, width) {
    elem = (typeof(div) == "string") ? document.getElementById(div) : div;
    if (!div || typeof(div) != "object") {
        return false;
        }
    div.style.height = height;
    div.style.width = width;
    return true;
    }

(Yes, I happen to like banner-style indents. So sue me.) There are still holes in this code -- I usually use something similar to Protoype's $() to fetch the element(s) with more sophisticated type checking, default assumptions and iteration where necessary (as when a collection is returned). Don't "search the web" for scripts, since you will probably have to modify something you don't understand in order to make it work on your page -- learn the language.
 

smithee

New Member
Messages
45
Reaction score
2
Points
0
essellar, correct me if I'm wrong (as I haven't touched JavaScript for a while), but concerning this part of the code:

HTML:
elem = (typeof(div) == "string") ? document.getElementById(div) : div;

... shouldn't div.style.height = height; be elem.style.height = height; instead, as elem has been assigned the object information and perhaps not div? The same applies for div.style.width= width;.
 
Last edited:

essellar

Community Advocate
Community Support
Messages
3,295
Reaction score
227
Points
63
Actually, that's the result of an editing error (the posted code was excerpted from something else). Should have read:

Code:
function resizeElement(div, height, width) {
    div = (typeof(div) == "string") ? document.getElementById(div) : div;
    if (!div || typeof(div) != "object") {
        return false;
        }
    div.style.height = height;
    div.style.width = width;
    return true;
    }

Thanks for the sharp eyes -- but why would you change "div" to read "elem" in four places when changing "elem" to read "div" once would have done the same thing, and without introducing an unnecessary variable?
 
Last edited:

smithee

New Member
Messages
45
Reaction score
2
Points
0
Yeah that's a good point, I suppose I've missed that whilst glancing over the provided code late last night.

@medina... What essellar has provided should be sufficient enough to meet your requirements; no Ajax here needed at all. If you run into any more trouble, just post another message and we'll be happy to help.
 
Top