Current location: Hot Scripts Forums » General Web Coding » JavaScript » else is not working


else is not working

Reply
  #1 (permalink)  
Old 12-01-09, 02:32 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 63
Thanks: 3
Thanked 0 Times in 0 Posts
else is not working

hi all

can anybody tell why else is not working

Code:
<script type="text/JavaScript">
var screenwidth = screen.width;
if(screenwidth <= 1024) {
document.write('<img src="image.jpg" width="1000">');
}
else
{
document.write('<img src="image.jpg" width="1250">');
}
</script>
vineet

Last edited by vinpkl; 12-01-09 at 02:33 AM. Reason: image
Reply With Quote
  #2 (permalink)  
Old 12-01-09, 06:06 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
I think it is due to the 'screen.width' assignment.

Use an alert to display the value.

alert(screen.width);
Reply With Quote
  #3 (permalink)  
Old 12-01-09, 06:12 AM
vinpkl vinpkl is offline
Newbie Coder
 
Join Date: Oct 2008
Posts: 63
Thanks: 3
Thanked 0 Times in 0 Posts
hi wirehopper

thanks for the reply. its working now but i have to refresh page everytime i change resolution.

i think thats the way javascript works.

vineet
Reply With Quote
  #4 (permalink)  
Old 12-01-09, 07:03 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
Quote:
Originally Posted by vinpkl View Post
hi wirehopper

thanks for the reply. its working now but i have to refresh page everytime i change resolution.

i think thats the way javascript works.

vineet
Your absolutely right.
Javascript works on the document.
Javascript can only detect changes to the document.
And the document is being displayed by the browser.
Every time you load the document into the browser, the Javascript will run again.
Changing the resolution of your monitor does not reload the document into the browser.
So if you are resizing the browser, Javascript can detect that.
But Javascript can not detect the fact that you changed the resolution of the monitor.
And as you already know, Javascript can detect the current resolution of the monitor when it is reloaded into the browser.
__________________
Jerry Broughton

Last edited by job0107; 12-01-09 at 07:08 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
Echo not working earthone PHP 3 10-06-09 12:02 AM
CSS not working in mozilla ashokdudhade CSS 6 07-05-08 01:04 AM
[SOLVED] Make Rewrite Modul Working in Windows, cause .htaccess ist not working specialex Web Servers 5 04-09-08 11:07 AM
[SOLVED] isLeapYear not working? viper2843 Everything Java 2 05-17-04 06:11 PM
If/else statement working...but not working mdhall PHP 13 10-16-03 08:47 AM


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