473,320 Members | 1,957 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help Please with Button Actions - JavaScript

Can any one please help me...I am new to JavaScript and I have been
struggling with this code for days now and can't figure it out.

I would like to get the Buttons to correspond with the action to
either a) generate numbers b) Prompts a user to locate a web page c)
go to previous page in history list d) Loads next page in history list
e) Promps the user for a URL and loads the web page in a new window f)
and Re-Sizes the window.

Please view my coding below, the only button that seems to work is
'Print'.

What am I doing incorrectly here? Can anyone tell me please or help me
solve this problem?

Thanks so much....

<HTML>
<HEAD>

<TITLE>Numbers per Loto Winners - JavaScript Button Action</TITLE>

<SCRIPT LANGUAGE="JavaScript">

<!--

function DrawNumbers( )
{
for (var x=1; x<7;x++)
{
var num = Math.round(math.random( )*100;
switch (x)
{
case 1:
document.frmNumbers.txtnum1.value = num;
break

case 2:
document.frmNumbers.txtnum2.value = num;
break

case 3:
document.frmNumbers.txtnum3.value = num;
break

case 4:
document.frmNumbers.txtnum4.value = num;
break

case 5:
document.frmNumbers.txtnum5.value = num;
break

case 6:
document.frmNumbers.txtnum6.value = num;
break

default: alert("x doesn't match")
}
}
}

function prompt( )
{
var strFind
strFind=prompt("Weekly Employees")
window.find(strFind)
}

function back( )
{ var back
back=Go back
window.back( )
}

function forward( )
{
window.forward( )
}

function home( )
{
window.home( )
}

function openwindow( )
{
window.open("http://www.cdicollge.com")
}

function response( )
{
var response
response = confirm("Do you wish to print this page?")
if (response = true)
window.print( )
else
alert("Printing has been rejected")
}

function ResizeBy( )
{
var Width = window.outerWidth / 2
var Height = window.outerHeight / 2
window.resizeBy(Width,Height)
}

function ResizeTo ( )
{
window.resizeTo(300,300)
}

//-->

</SCRIPT>
</HEAD>

<BODY>
<H1 Align=center> <Font Face=Arial Color=Red> Weekly Employee Lottery
Draw </Font></H1>
<Center>
<Font Face=Arial Size=3 Color=Blue>
<FORM NAME="FrmNumbers">

Number 1<INPUT TYPE="text" NAME="txtnum1" VALUE="0" SIZE="10"><BR>
Number 2<INPUT TYPE="text" NAME="txtnum2" VALUE="0" SIZE="10"><BR>
Number 3<INPUT TYPE="text" NAME="txtnum3" VALUE="0" SIZE="10"><BR>
Number 4<INPUT TYPE="text" NAME="txtnum4" VALUE="0" SIZE="10"><BR>
Number 5<INPUT TYPE="text" NAME="txtnum5" VALUE="0" SIZE="10"><BR>
Number 6<INPUT TYPE="text" NAME="txtnum6" VALUE="0"
SIZE="10"><BR><BR><HR><HR>

<INPUT TYPE="button" NAME="cmdDraw" VALUE="Generate Numbers"
onClick="DrawNumbers ( )">
</FORM>

<FORM NAME="buttonAction">

<INPUT TYPE="button" NAME="buttonPrompt" VALUE="Find"
onClick="window.prompt( )">
<INPUT TYPE="button" NAME="buttonBack" VALUE="Go Back"
onClick="window.back( )">
<INPUT TYPE="button" NAME="buttonForward" VALUE="Go Forward"
onClick="window.forward( )">
<INPUT TYPE="button" NAME="buttonHome" VALUE="Home"
onClick="window.home( )">
<INPUT TYPE="button" NAME="buttonWindow" VALUE="Open Window"
onclick="openwindow()">
<INPUT TYPE="button" NAME="buttonPrint" VALUE="Print"
onClick="window.print()">
<INPUT TYPE="button" NAME="buttonResizeBy"VALUE="Resize"
onClick="ResizeBy(-50,-50)">
<INPUT TYPE="button" NAME="buttonResizeTo"VALUE="Resize"
onClick="ResizeTo(300,300)">

</FORM>
</FONT>
</CENTER>

</BODY>
</HTML>
Jul 23 '05 #1
5 2243
view below. I fixed up your code. Please compare your code to mine
below and you will what I did.

Please note that JavaScript is case sensitive and does not like when you
create function and than call another function with the same name.

If you have any other questions, let me know or post to the group.

Orlando, aka, Cycloneous

<HTML>
<HEAD>

<TITLE>Numbers per Loto Winners - JavaScript Button Action</TITLE>

<SCRIPT LANGUAGE="JavaScript">

<!--

function DrawNumbers( )
{
for (var x=1; x<7;x++)
{
var num = Math.round(Math.random( )*100);
switch (x)
{
case 1:
document.frmNumbers.txtnum1.value = num;
break

case 2:
document.frmNumbers.txtnum2.value = num;
break

case 3:
document.frmNumbers.txtnum3.value = num;
break

case 4:
document.frmNumbers.txtnum4.value = num;
break

case 5:
document.frmNumbers.txtnum5.value = num;
break

case 6:
document.frmNumbers.txtnum6.value = num;
break

default: alert("x doesn't match")
}
}
}

function ask( )
{
var strFind
strFind=prompt("Weekly Employees")
window.find(strFind)
}

function back( )
{ var back
back="Go back"
window.history.go(-1);
}

function forward( )
{
window.history.go(1);
}

function goHome( )
{
window.home();
}

function openWin( )
{
window.open("http://www.cdicollge.com");
}

function response( )
{
var resp;
resp = confirm("Do you wish to print this page?");
if (resp = true)
window.print( );
else
alert("Printing has been rejected")
}

function ReSizeWin( )
{
var Width = window.outerWidth / 2
var Height = window.outerHeight / 2
window.resizeBy(Width,Height)
}

function ReSizeWinTo ( )
{
window.resizeTo(300,300)
}

//-->

</SCRIPT>
</HEAD>

<BODY>
<H1 Align=center> <Font Face=Arial Color=Red> Weekly Employee Lottery
Draw </Font></H1>
<Center>
<Font Face=Arial Size=3 Color=Blue>

<!-- FrmNumbers -->
<FORM NAME="frmNumbers">

Number 1<INPUT TYPE="text" NAME="txtnum1" VALUE="0" SIZE="10"><BR>
Number 2<INPUT TYPE="text" NAME="txtnum2" VALUE="0" SIZE="10"><BR>
Number 3<INPUT TYPE="text" NAME="txtnum3" VALUE="0" SIZE="10"><BR>
Number 4<INPUT TYPE="text" NAME="txtnum4" VALUE="0" SIZE="10"><BR>
Number 5<INPUT TYPE="text" NAME="txtnum5" VALUE="0" SIZE="10"><BR>
Number 6<INPUT TYPE="text" NAME="txtnum6" VALUE="0"
SIZE="10"><BR><BR><HR><HR>

<INPUT TYPE="button" NAME="cmdDraw" VALUE="Generate Numbers"
onClick="DrawNumbers ( )">
</FORM>

<FORM NAME="buttonAction">

<INPUT TYPE="button" NAME="buttonPrompt" VALUE="Find"
onClick="ask( )">
<INPUT TYPE="button" NAME="buttonBack" VALUE="Go Back"
onClick="back( )">
<INPUT TYPE="button" NAME="buttonForward" VALUE="Go Forward"
onClick="forward( )">
<INPUT TYPE="button" NAME="buttonHome" VALUE="Home"
onClick="goHome( )">
<INPUT TYPE="button" NAME="buttonWindow" VALUE="Open Window"
onclick="openWin()">
<INPUT TYPE="button" NAME="buttonPrint" VALUE="Print"
onClick="window.print()">
<INPUT TYPE="button" NAME="buttonResizeBy"VALUE="Resize"
onClick="ReSizeWin()">
<INPUT TYPE="button" NAME="buttonResizeTo"VALUE="Resize"
onClick="ReSizeWinTo()">

</FORM>
</FONT>
</CENTER>

</BODY>
</HTML>

TrvlOrm wrote:
Can any one please help me...I am new to JavaScript and I have been
struggling with this code for days now and can't figure it out.

I would like to get the Buttons to correspond with the action to
either a) generate numbers b) Prompts a user to locate a web page c)
go to previous page in history list d) Loads next page in history list
e) Promps the user for a URL and loads the web page in a new window f)
and Re-Sizes the window.

Please view my coding below, the only button that seems to work is
'Print'.

What am I doing incorrectly here? Can anyone tell me please or help me
solve this problem?

Thanks so much....

<HTML>
<HEAD>

<TITLE>Numbers per Loto Winners - JavaScript Button Action</TITLE>

<SCRIPT LANGUAGE="JavaScript">

<!--

function DrawNumbers( )
{
for (var x=1; x<7;x++)
{
var num = Math.round(math.random( )*100;
switch (x)
{
case 1:
document.frmNumbers.txtnum1.value = num;
break

case 2:
document.frmNumbers.txtnum2.value = num;
break

case 3:
document.frmNumbers.txtnum3.value = num;
break

case 4:
document.frmNumbers.txtnum4.value = num;
break

case 5:
document.frmNumbers.txtnum5.value = num;
break

case 6:
document.frmNumbers.txtnum6.value = num;
break

default: alert("x doesn't match")
}
}
}

function prompt( )
{
var strFind
strFind=prompt("Weekly Employees")
window.find(strFind)
}

function back( )
{ var back
back=Go back
window.back( )
}

function forward( )
{
window.forward( )
}

function home( )
{
window.home( )
}

function openwindow( )
{
window.open("http://www.cdicollge.com")
}

function response( )
{
var response
response = confirm("Do you wish to print this page?")
if (response = true)
window.print( )
else
alert("Printing has been rejected")
}

function ResizeBy( )
{
var Width = window.outerWidth / 2
var Height = window.outerHeight / 2
window.resizeBy(Width,Height)
}

function ResizeTo ( )
{
window.resizeTo(300,300)
}

//-->

</SCRIPT>
</HEAD>

<BODY>
<H1 Align=center> <Font Face=Arial Color=Red> Weekly Employee Lottery
Draw </Font></H1>
<Center>
<Font Face=Arial Size=3 Color=Blue>
<FORM NAME="FrmNumbers">

Number 1<INPUT TYPE="text" NAME="txtnum1" VALUE="0" SIZE="10"><BR>
Number 2<INPUT TYPE="text" NAME="txtnum2" VALUE="0" SIZE="10"><BR>
Number 3<INPUT TYPE="text" NAME="txtnum3" VALUE="0" SIZE="10"><BR>
Number 4<INPUT TYPE="text" NAME="txtnum4" VALUE="0" SIZE="10"><BR>
Number 5<INPUT TYPE="text" NAME="txtnum5" VALUE="0" SIZE="10"><BR>
Number 6<INPUT TYPE="text" NAME="txtnum6" VALUE="0"
SIZE="10"><BR><BR><HR><HR>

<INPUT TYPE="button" NAME="cmdDraw" VALUE="Generate Numbers"
onClick="DrawNumbers ( )">
</FORM>

<FORM NAME="buttonAction">

<INPUT TYPE="button" NAME="buttonPrompt" VALUE="Find"
onClick="window.prompt( )">
<INPUT TYPE="button" NAME="buttonBack" VALUE="Go Back"
onClick="window.back( )">
<INPUT TYPE="button" NAME="buttonForward" VALUE="Go Forward"
onClick="window.forward( )">
<INPUT TYPE="button" NAME="buttonHome" VALUE="Home"
onClick="window.home( )">
<INPUT TYPE="button" NAME="buttonWindow" VALUE="Open Window"
onclick="openwindow()">
<INPUT TYPE="button" NAME="buttonPrint" VALUE="Print"
onClick="window.print()">
<INPUT TYPE="button" NAME="buttonResizeBy"VALUE="Resize"
onClick="ResizeBy(-50,-50)">
<INPUT TYPE="button" NAME="buttonResizeTo"VALUE="Resize"
onClick="ResizeTo(300,300)">

</FORM>
</FONT>
</CENTER>

</BODY>
</HTML>

Jul 23 '05 #2
In article <fa*************************@posting.google.com> ,
ks*****@shaw.ca enlightened us with...
Can any one please help me...I am new to JavaScript and I have been
struggling with this code for days now and can't figure it out.

I would like to get the Buttons to correspond with the action to
either a) generate numbers b) Prompts a user to locate a web page c)
go to previous page in history list d) Loads next page in history list
e) Promps the user for a URL and loads the web page in a new window f)
and Re-Sizes the window.

Please view my coding below, the only button that seems to work is
'Print'.

What am I doing incorrectly here?


Lots. See code below. Tested in Mozilla and IE.
Fix that random number function, too. It seems to only return 0 or 100.
The home button still doesn't work. I don't think there's a window.home.
Check into that. Same for the find button.
Forward won't work unless there is actually a page forward in history.
Vice versa with back.
<HTML>
<HEAD>
<TITLE>Numbers per Loto Winners - JavaScript Button Action</TITLE>
<SCRIPT LANGUAGE="JavaScript" type="text/javascript">

<!--

function DrawNumbers( )
{
for (var x=1; x<7;x++)
{
var num = Math.round(Math.random( ))*100;
document.forms["FrmNumbers"].elements["txtnum"+x].value = num;
}
}

function my_prompt( )
{
var strFind;
strFind=prompt("Weekly Employees");
window.find(strFind)
}

function my_back( )
{
window.back( );
}

function my_forward( )
{
window.forward( );
}

function my_home( )
{
window.home( );
}

function openwindow( )
{
window.open("http://www.cdicollge.com");
}

function my_print( )
{
var response;
response = confirm("Do you wish to print this page?");
if (response == true)
window.print( );
else
alert("Printing has been rejected");
}

function ResizeBy( )
{
var Width = window.outerWidth / 2;
var Height = window.outerHeight / 2;
window.resizeBy(Width,Height);
}

function ResizeTo ( )
{
window.resizeTo(300,300);
}

//-->

</SCRIPT>
</HEAD>

<BODY>
<H1 Align=center> <Font Face=Arial Color=Red> Weekly Employee Lottery
Draw </Font></H1>
<Center>
<Font Face=Arial Size=3 Color=Blue>
<FORM NAME="FrmNumbers">

Number 1<INPUT TYPE="text" NAME="txtnum1" VALUE="0" SIZE="10"><BR>
Number 2<INPUT TYPE="text" NAME="txtnum2" VALUE="0" SIZE="10"><BR>
Number 3<INPUT TYPE="text" NAME="txtnum3" VALUE="0" SIZE="10"><BR>
Number 4<INPUT TYPE="text" NAME="txtnum4" VALUE="0" SIZE="10"><BR>
Number 5<INPUT TYPE="text" NAME="txtnum5" VALUE="0" SIZE="10"><BR>
Number 6<INPUT TYPE="text" NAME="txtnum6" VALUE="0"
SIZE="10"><BR><BR><HR><HR>

<INPUT TYPE="button" NAME="cmdDraw" VALUE="Generate Numbers"
onClick="DrawNumbers ( )">
</FORM>

<FORM NAME="buttonAction">

<INPUT TYPE="button" NAME="buttonPrompt" VALUE="Find"
onClick="my_prompt( )">
<INPUT TYPE="button" NAME="buttonBack" VALUE="Go Back"
onClick="my_back( )">
<INPUT TYPE="button" NAME="buttonForward" VALUE="Go Forward"
onClick="my_forward( )">
<INPUT TYPE="button" NAME="buttonHome" VALUE="Home"
onClick="window.home( )">
<INPUT TYPE="button" NAME="buttonWindow" VALUE="Open Window"
onclick="openwindow()">
<INPUT TYPE="button" NAME="buttonPrint" VALUE="Print"
onClick="my_print()">
<INPUT TYPE="button" NAME="buttonResizeBy"VALUE="Resize"
onClick="ResizeBy(-50,-50)">
<INPUT TYPE="button" NAME="buttonResizeTo"VALUE="Resize"
onClick="ResizeTo(300,300)">

</FORM>
</FONT>
</CENTER>

</BODY>
</HTML>

--
--
~kaeli~
No one is listening until you make a mistake.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #3
TrvlOrm wrote on 05 mei 2004 in comp.lang.javascript:
function DrawNumbers( )
{
for (var x=1; x<7;x++)
{
var num = Math.round(math.random( )*100;
switch (x)
{
case 1:
document.frmNumbers.txtnum1.value = num;
break

case 2:
document.frmNumbers.txtnum2.value = num;
break

case 3:
document.frmNumbers.txtnum3.value = num;
break

case 4:
document.frmNumbers.txtnum4.value = num;
break

case 5:
document.frmNumbers.txtnum5.value = num;
break

case 6:
document.frmNumbers.txtnum6.value = num;
break

default: alert("x doesn't match")
}
}
}

Commenting only on this function
[M in Math should be capitalized both times !!!!]

function DrawNumbers( ){
for (var x=1; x<7;x++) {
document.frmNumbers["txtnum"+x].value =
Math.round(Math.random()*100;
}
}

This should do the same

not tested

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 23 '05 #4
JRS: In article <Xn********************@194.109.133.29>, seen in
news:comp.lang.javascript, Evertjan. <ex**************@interxnl.net>
posted at Wed, 5 May 2004 18:26:36 :

function DrawNumbers( ){
for (var x=1; x<7;x++) {
document.frmNumbers["txtnum"+x].value =
Math.round(Math.random()*100;
}
}

This should do the same

not tested

I would have suggested something similar, though probably using function
Random (see FAQ 4.22, as you know). BTW, that function has neither the
missing ) nor the wrong Method of Math.

But the OP wishes for a Draw, and the essence of a Draw is that numbers
cannot repeat. The chance of a repeat above must exceed 10%, at a
guess.

A Draw is in essence a partial Deal, and if the FAQ is searched for
that, sec. 4.22 will be found, with a suitable Link.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
Thank you so much for all the help on this. With a bit of playing
around, I finally got it to work.

Thanks again.

Dr John Stockton <sp**@merlyn.demon.co.uk> wrote in message news:<WP**************@merlyn.demon.co.uk>...
JRS: In article <Xn********************@194.109.133.29>, seen in
news:comp.lang.javascript, Evertjan. <ex**************@interxnl.net>
posted at Wed, 5 May 2004 18:26:36 :

function DrawNumbers( ){
for (var x=1; x<7;x++) {
document.frmNumbers["txtnum"+x].value =
Math.round(Math.random()*100;
}
}

This should do the same

not tested

I would have suggested something similar, though probably using function
Random (see FAQ 4.22, as you know). BTW, that function has neither the
missing ) nor the wrong Method of Math.

But the OP wishes for a Draw, and the essence of a Draw is that numbers
cannot repeat. The chance of a repeat above must exceed 10%, at a
guess.

A Draw is in essence a partial Deal, and if the FAQ is searched for
that, sec. 4.22 will be found, with a suitable Link.

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Lucy | last post by:
help! javascript inline of an HTML to open an HTML in a target window. Something like... <html> <head> <title>test</title> </head> <body>
1
by: Allen | last post by:
I am trying to add an additional photo/hyperlink to the company web site (I didn't create it) without any luck. The mouseover feature 'highlights' pics by swapping them with another pic using this...
2
by: Jackson Yap | last post by:
can someone kind enough to help me look at the attached html and js file? Why is it that the javascript menu could not work at www.apchosting.net but could work at...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
7
by: Tigger | last post by:
Dear Experts, I am working on ASP.NET. I have got a problem related to the usage of Javascript in ASP.NET. Please help. The story is the following: 1) I am developing an ASP.NET application. I...
2
by: Dave Ekhaus | last post by:
hi i'm new to javascript. i'm hoping to get some help and find out if what i want to do is possible and - assuming it is, get some tips on how to accomplish the task. ok - assume i have a...
5
by: Jeremy | last post by:
Hi all, I have database actions that will potentially take several seconds to complete. My normal page uses AJAX so keeping the user informed of what is happening is not a problem. ...
53
by: souporpower | last post by:
Hello All I am trying to activate a link using Jquery. Here is my code; <html> <head> <script type="text/javascript" src="../../resources/js/ jquery-1.2.6.js"</script> <script...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.