Current location: Hot Scripts Forums » General Web Coding » JavaScript » where i am going wrong


where i am going wrong

Reply
  #1 (permalink)  
Old 08-03-11, 04:18 AM
AhmedX AhmedX is offline
New Member
 
Join Date: Jul 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
where i am going wrong

i wrote this code that resize the hight and width of an image but i am facing a problem the code i wrote is made of two function i want to run only one function at time want to add an if statment to check the hight and width are more than the max hight and width and for the function i want to add else if statment to check if the hight and width are less than the max hight and width i tried evreything i could think of but there was no hope where i am going wrong

here is my code java script
Code:
<script type="text/javascript">
var w=document.getElementById("h1").getAttribute("width");
var h=document.getElementById("h1").getAttribute("height");
var smallImage
var BigImage
if(w<217&&h<192){
smallImage=function resizesSmallImage(){//do the function on load
var w=document.getElementById("h1").getAttribute("width");

var h=document.getElementById("h1").getAttribute("height");

var maxheight=192;
var maxwidth=217;
var diffrance;
var i;
if(w>h){
diffrance=maxwidth-w;//197
for(i=w;i<diffrance;i++){
    w++;
    h++;
    if(h==maxheight||w==maxwidth){break;}
}
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}// compare number of the same amount of digits ex:10 with 200
else if(w<h){
    diffrance=maxheight-h;//204
for(i=h;i<diffrance;i++){
    w++;
    h++;
    if(h==maxheight||w==maxwidth){break;}
}
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}

else{    
for(i=h;i<maxheight;i++){
    w++;
    h++;
if(h==maxheight||w==maxwidth){break;}
}
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}

}//end function
window.onload=smallImage
}//end SMALL if

else if(w>217&&h>192){
BigImage=function resizesBigImage(){
var w=document.getElementById("h1").getAttribute("width");
var h=document.getElementById("h1").getAttribute("height");

var maxheight=192;
var maxwidth=217;
var diffrance;
var i;
if(w>h){
diffrance=w-maxwidth;//600
for(i=w;i>maxwidth;i--){
    w--;
    h--;
if(h==maxheight||w==maxwidth){break;}
}
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}// compare number of the same amount of digits ex:10 with 200
else if(w<h){
    diffrance=h-maxheight;//500
for(i=h;i>maxheight;i--){
    w--;
    h--;
if(h==maxheight||w==maxwidth){break;}
}//end for
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}//end else if

else{
    for(i=h;i>maxheight;i--){
    w--;
    h--;
if(h==maxheight||w==maxwidth){break;}
}
w=document.getElementById("h1").setAttribute("width",w)
h=document.getElementById("h1").setAttribute("height",h)
}

}//end function
window.onload=BigImage
}
</script>
here is my HTML
HTML Code:
<img src="images.jpeg" id="h1"  width="50" height="70" />

Last edited by Nico; 08-03-11 at 04:49 AM.
Reply With Quote
  #2 (permalink)  
Old 11-21-11, 11:05 AM
DLJ DLJ is offline
Newbie Coder
 
Join Date: Nov 2011
Location: 303 See Other
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
What is it exactly that you want? Using a text box to change the width and height or...?

Instead of

Code:
w=document.getElementById("h1").setAttribute("width",w);
h=document.getElementById("h1").setAttribute("height",h);
Try this

Code:
w=document.getElementById("h1").width="";
h=document.getElementById("h1").height="";
Also, check your code for missing semicolons. I just glanced through, but I saw at least four lines missing them. Specifically, the lines containing
Code:
document.getElementById("h1").setAttribute("width",w)
Hope this helps!

Last edited by DLJ; 11-21-11 at 11:07 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
what's wrong with my laptop? sunny5 The Lounge 4 05-20-11 01:40 AM
Whats wrong with this code? qldguy27au PHP 1 11-16-10 04:54 PM
what have I done wrong? php attachments for mail moe180 PHP 0 06-10-09 08:14 AM
Warning: Wrong parameter count... Tim Mousel PHP 5 01-23-06 12:10 PM


All times are GMT -5. The time now is 02:05 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.