You are not logged in.
I posted this over at Linuxquestions.org but thought I'd try my luck here as well...
I want to resize a DIV on a "onclick"-event in a web page. It's nearly working but I am having difficulties adding two numbers together where one of these numbers is in a string variable.
"popup" in the code below is the id of the DIV.
The div is "styled" like this:
DIV.popup {visibility:hidden; width:0px; height:20px; position:absolute; background-color:red}
This is how it looks:
function zoomIn() {
//Make the DIV visible (hidden by default).
popup.style.visibility = 'visible';
//Number of steps, pixels, to increase the DIV-width.
step=10;
//Parse eg "100px" so that only "100" is left.
currWidth=popup.currentStyle.width;
currWidth=currWidth.substring(0, (currWidth.length-2));
currHeight=popup.currentStyle.height;
currHeight=currHeight.substring(0, (currHeight.length-2));
//If the width of the DIV is < 500, then resize.
if(currWidth < 500) {
// THIS IS WHERE IT FAILS.
popup.style.width=currWidth+step;
//Call function zoomIn() again after 1000ms.
setTimeout("zoomIn()", 1000);
}
}
So... How on earth do I add the variable "currWidth", which should be a string variable, with the variable "step", which holds an integer, without getting type mismatch or results like this: 10+10=1010?
I have tried toInt(), parseint() etc but everything I throw at it keeps getting back with an error.
It feels like this should be dead easy. Anyone?
Offline
Just got an answer from LQ. It turns out that it works very well if you use parseInt() and not parseint() as I did.
Never thought it would be case sensitive this javascript thingy. Oh well...
Offline
You could also use eval().
Offline