Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if else?? getMinutes()

Status
Not open for further replies.

grayliner

Programmer
Feb 2, 2002
10
0
0
US
var seasons = new Array(4)
seasons[0] = "Fall"
seasons[1] = "Winter"
seasons[2] = "Spring"
seasons[3] = "Summer"

var browser = navigator.appName
var version = navigator.appVersion


function promptwindow() {

var promptwin = prompt("What is your name?","");

if ( (promptwin == null) || (promptwin == "") )
promptwin = "NO DATA"

newWindow=window.open("","","status,height=200,width=300");
newWindow.document.open();
newWindow.document.write('<html><body>');
newWindow.document.write(promptwin);
newWindow.document.write('<br><strong>Browser:</strong> ', browser);
newWindow.document.write('<br><strong>Version:</strong> ', version);
newWindow.document.write('<br><strong>Time:</strong> ', getMinutes());
newWindow.document.write('</body></html>');
newWindow.document.close();
}

ok so what i need is if the browser deteched is in IE, for it to say &quot;fall&quot; in the array found above, and if it is Netscape to say &quot;Winter&quot; if other &quot;Spring&quot;

also does anyone know how to display the minutes and hours? (hh:mm)??
both of these need to appear in the newWindow.
i thought it was 'getMinutes' but its not working
 
the minutes and hours thing i can answer..
Code:
var cute = new Date();
var hour = cute.getHours();
var minutes = cute.getMinutes();
if (hour > &quot;12&quot;)
hours = (hour * 1) - 12;
else
hours = hour;
var time = hour + &quot;:&quot; + minutes;
The pen is mightier than the sword.
 
you would write the time up there like this, btw:
newWindow.document.write(time);

ok now to the browser detection:
Code:
if (browser == &quot;Microsoft Internet Explorer&quot;)
newWindow.doucment.write(seasons[0]);
elseif (browser == &quot;Netscape&quot;)
newWindow.document.write(seasons[1]);
else 
newWindow.document.write(seasons[2]);
The pen is mightier than the sword.
 
hey where do i put those in my code???
i'm a little confused about that.

sorry i'm a little new to this javascript thing, and the book i have isn't very helpful.
 
grayliner: Considering how many threads you've started about just this one project, I suggest going to this site:


It teaches basic JavaScript (And is where I learned the basics). Maybe someday I should set up a site similar to it for teaching advanced javascript.
 
OK, accumulating what was said in all the posts and threads about this:

var seasons = new Array(4)
seasons[0] = &quot;Fall&quot;
seasons[1] = &quot;Winter&quot;
seasons[2] = &quot;Spring&quot;
seasons[3] = &quot;Summer&quot;

var browser = navigator.appName;
var version = navigator.appVersion;

if (browser == &quot;Microsoft Internet Explorer&quot;)
season = seasons[0]
else if (browser == &quot;Netscape&quot;)
season = seasons[1]
else
season = seasons[2];

var cute = new Date();
var hour = cute.getHours();
var minutes = cute.getMinutes();
if (hour > &quot;12&quot;)
hours = (hour * 1) - 12
else
hours = hour;
var time = hour + &quot;:&quot; + minutes;

function promptwindow() {

var promptwin = prompt(&quot;What is your name?&quot;,&quot;&quot;);

if ( (promptwin == null) || (promptwin == &quot;&quot;) )
promptwin = &quot;NO DATA&quot;

newWindow=window.open(&quot;&quot;,&quot;&quot;,&quot;status,height=200,width=300&quot;);
newWindow.document.open();
newWindow.document.write('<html><body>');

//data from prompt win
newWindow.document.write(promptwin);

//browser data
newWindow.document.write('<br><strong>Browser:</strong> ', browser);
newWindow.document.write('<br><strong>Version:</strong> ', version);

//season according to user's browser
newWindow.document.writeln(season);

//currect time in hh:mm format
newWindow.document.writeln(time);

newWindow.document.write('</body></html>');
newWindow.document.close();
}


I slightly corrected the syntax.
You shouldn't place ; at the line's end if the next line is &quot;else&quot;.

Also, I changed document.write to document.writeln in some places. This will save you some chars if you want something to appear on the next line.

Hope this is all.
 
wow... that would be quite a bit of code... Just being a little picky, but the above code would be a lot nicer if you just set a single variable to equal
Code:
newWindow.document
to make the code shorter.
 
Well, it's not the only change that I'd like to add to make it shorter...
This code is collected from 3 different people (at least) and I didn't want to add another confusion to grayliner.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top