Help Please with Button Actions - JavaScript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TrvlOrm

    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>Number s per Loto Winners - JavaScript Button Action</TITLE>

    <SCRIPT LANGUAGE="JavaS cript">

    <!--

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

    case 2:
    document.frmNum bers.txtnum2.va lue = num;
    break

    case 3:
    document.frmNum bers.txtnum3.va lue = num;
    break

    case 4:
    document.frmNum bers.txtnum4.va lue = num;
    break

    case 5:
    document.frmNum bers.txtnum5.va lue = num;
    break

    case 6:
    document.frmNum bers.txtnum6.va lue = num;
    break

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

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

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

    function forward( )
    {
    window.forward( )
    }

    function home( )
    {
    window.home( )
    }

    function openwindow( )
    {
    window.open("ht tp://www.cdicollge.c om")
    }

    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.outerWid th / 2
    var Height = window.outerHei ght / 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="FrmNumber s">

    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="DrawNu mbers ( )">
    </FORM>

    <FORM NAME="buttonAct ion">

    <INPUT TYPE="button" NAME="buttonPro mpt" VALUE="Find"
    onClick="window .prompt( )">
    <INPUT TYPE="button" NAME="buttonBac k" VALUE="Go Back"
    onClick="window .back( )">
    <INPUT TYPE="button" NAME="buttonFor ward" VALUE="Go Forward"
    onClick="window .forward( )">
    <INPUT TYPE="button" NAME="buttonHom e" VALUE="Home"
    onClick="window .home( )">
    <INPUT TYPE="button" NAME="buttonWin dow" VALUE="Open Window"
    onclick="openwi ndow()">
    <INPUT TYPE="button" NAME="buttonPri nt" VALUE="Print"
    onClick="window .print()">
    <INPUT TYPE="button" NAME="buttonRes izeBy"VALUE="Re size"
    onClick="Resize By(-50,-50)">
    <INPUT TYPE="button" NAME="buttonRes izeTo"VALUE="Re size"
    onClick="Resize To(300,300)">

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

    </BODY>
    </HTML>
  • Cycloneous Echevarria

    #2
    Re: Help Please with Button Actions - JavaScript

    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>Number s per Loto Winners - JavaScript Button Action</TITLE>

    <SCRIPT LANGUAGE="JavaS cript">

    <!--

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

    case 2:
    document.frmNum bers.txtnum2.va lue = num;
    break

    case 3:
    document.frmNum bers.txtnum3.va lue = num;
    break

    case 4:
    document.frmNum bers.txtnum4.va lue = num;
    break

    case 5:
    document.frmNum bers.txtnum5.va lue = num;
    break

    case 6:
    document.frmNum bers.txtnum6.va lue = num;
    break

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

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

    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("ht tp://www.cdicollge.c om");
    }

    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.outerWid th / 2
    var Height = window.outerHei ght / 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="frmNumber s">

    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="DrawNu mbers ( )">
    </FORM>

    <FORM NAME="buttonAct ion">

    <INPUT TYPE="button" NAME="buttonPro mpt" VALUE="Find"
    onClick="ask( )">
    <INPUT TYPE="button" NAME="buttonBac k" VALUE="Go Back"
    onClick="back( )">
    <INPUT TYPE="button" NAME="buttonFor ward" VALUE="Go Forward"
    onClick="forwar d( )">
    <INPUT TYPE="button" NAME="buttonHom e" VALUE="Home"
    onClick="goHome ( )">
    <INPUT TYPE="button" NAME="buttonWin dow" VALUE="Open Window"
    onclick="openWi n()">
    <INPUT TYPE="button" NAME="buttonPri nt" VALUE="Print"
    onClick="window .print()">
    <INPUT TYPE="button" NAME="buttonRes izeBy"VALUE="Re size"
    onClick="ReSize Win()">
    <INPUT TYPE="button" NAME="buttonRes izeTo"VALUE="Re size"
    onClick="ReSize WinTo()">

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

    </BODY>
    </HTML>

    TrvlOrm wrote:
    [color=blue]
    > 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>Number s per Loto Winners - JavaScript Button Action</TITLE>
    >
    > <SCRIPT LANGUAGE="JavaS cript">
    >
    > <!--
    >
    > function DrawNumbers( )
    > {
    > for (var x=1; x<7;x++)
    > {
    > var num = Math.round(math .random( )*100;
    > switch (x)
    > {
    > case 1:
    > document.frmNum bers.txtnum1.va lue = num;
    > break
    >
    > case 2:
    > document.frmNum bers.txtnum2.va lue = num;
    > break
    >
    > case 3:
    > document.frmNum bers.txtnum3.va lue = num;
    > break
    >
    > case 4:
    > document.frmNum bers.txtnum4.va lue = num;
    > break
    >
    > case 5:
    > document.frmNum bers.txtnum5.va lue = num;
    > break
    >
    > case 6:
    > document.frmNum bers.txtnum6.va lue = num;
    > break
    >
    > default: alert("x doesn't match")
    > }
    > }
    > }
    >
    > function prompt( )
    > {
    > var strFind
    > strFind=prompt( "Weekly Employees")
    > window.find(str Find)
    > }
    >
    > function back( )
    > { var back
    > back=Go back
    > window.back( )
    > }
    >
    > function forward( )
    > {
    > window.forward( )
    > }
    >
    > function home( )
    > {
    > window.home( )
    > }
    >
    > function openwindow( )
    > {
    > window.open("ht tp://www.cdicollge.c om")
    > }
    >
    > 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.outerWid th / 2
    > var Height = window.outerHei ght / 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="FrmNumber s">
    >
    > 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="DrawNu mbers ( )">
    > </FORM>
    >
    > <FORM NAME="buttonAct ion">
    >
    > <INPUT TYPE="button" NAME="buttonPro mpt" VALUE="Find"
    > onClick="window .prompt( )">
    > <INPUT TYPE="button" NAME="buttonBac k" VALUE="Go Back"
    > onClick="window .back( )">
    > <INPUT TYPE="button" NAME="buttonFor ward" VALUE="Go Forward"
    > onClick="window .forward( )">
    > <INPUT TYPE="button" NAME="buttonHom e" VALUE="Home"
    > onClick="window .home( )">
    > <INPUT TYPE="button" NAME="buttonWin dow" VALUE="Open Window"
    > onclick="openwi ndow()">
    > <INPUT TYPE="button" NAME="buttonPri nt" VALUE="Print"
    > onClick="window .print()">
    > <INPUT TYPE="button" NAME="buttonRes izeBy"VALUE="Re size"
    > onClick="Resize By(-50,-50)">
    > <INPUT TYPE="button" NAME="buttonRes izeTo"VALUE="Re size"
    > onClick="Resize To(300,300)">
    >
    > </FORM>
    > </FONT>
    > </CENTER>
    >
    > </BODY>
    > </HTML>[/color]

    Comment

    • kaeli

      #3
      Re: Help Please with Button Actions - JavaScript

      In article <fa9bacd0.04050 50947.ac08931@p osting.google.c om>,
      ksorman@shaw.ca enlightened us with...[color=blue]
      > 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?[/color]

      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>Number s per Loto Winners - JavaScript Button Action</TITLE>
      <SCRIPT LANGUAGE="JavaS cript" 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(str Find)
      }

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

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

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

      function openwindow( )
      {
      window.open("ht tp://www.cdicollge.c om");
      }

      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.outerWid th / 2;
      var Height = window.outerHei ght / 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="FrmNumber s">

      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="DrawNu mbers ( )">
      </FORM>

      <FORM NAME="buttonAct ion">

      <INPUT TYPE="button" NAME="buttonPro mpt" VALUE="Find"
      onClick="my_pro mpt( )">
      <INPUT TYPE="button" NAME="buttonBac k" VALUE="Go Back"
      onClick="my_bac k( )">
      <INPUT TYPE="button" NAME="buttonFor ward" VALUE="Go Forward"
      onClick="my_for ward( )">
      <INPUT TYPE="button" NAME="buttonHom e" VALUE="Home"
      onClick="window .home( )">
      <INPUT TYPE="button" NAME="buttonWin dow" VALUE="Open Window"
      onclick="openwi ndow()">
      <INPUT TYPE="button" NAME="buttonPri nt" VALUE="Print"
      onClick="my_pri nt()">
      <INPUT TYPE="button" NAME="buttonRes izeBy"VALUE="Re size"
      onClick="Resize By(-50,-50)">
      <INPUT TYPE="button" NAME="buttonRes izeTo"VALUE="Re size"
      onClick="Resize To(300,300)">

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

      </BODY>
      </HTML>

      --
      --
      ~kaeli~
      No one is listening until you make a mistake.



      Comment

      • Evertjan.

        #4
        Re: Help Please with Button Actions - JavaScript

        TrvlOrm wrote on 05 mei 2004 in comp.lang.javas cript:
        [color=blue]
        > function DrawNumbers( )
        > {
        > for (var x=1; x<7;x++)
        > {
        > var num = Math.round(math .random( )*100;
        > switch (x)
        > {
        > case 1:
        > document.frmNum bers.txtnum1.va lue = num;
        > break
        >
        > case 2:
        > document.frmNum bers.txtnum2.va lue = num;
        > break
        >
        > case 3:
        > document.frmNum bers.txtnum3.va lue = num;
        > break
        >
        > case 4:
        > document.frmNum bers.txtnum4.va lue = num;
        > break
        >
        > case 5:
        > document.frmNum bers.txtnum5.va lue = num;
        > break
        >
        > case 6:
        > document.frmNum bers.txtnum6.va lue = num;
        > break
        >
        > default: alert("x doesn't match")
        > }
        >}
        >}[/color]


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

        function DrawNumbers( ){
        for (var x=1; x<7;x++) {
        document.frmNum bers["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)

        Comment

        • Dr John Stockton

          #5
          Re: Help Please with Button Actions - JavaScript

          JRS: In article <Xns94E0CFF6C29 18eejj99@194.10 9.133.29>, seen in
          news:comp.lang. javascript, Evertjan. <exjxw.hannivoo rt@interxnl.net >
          posted at Wed, 5 May 2004 18:26:36 :[color=blue]
          >
          >function DrawNumbers( ){
          > for (var x=1; x<7;x++) {
          > document.frmNum bers["txtnum"+x].value =
          > Math.round(Math .random()*100;
          > }
          >}
          >
          >This should do the same
          >
          >not tested[/color]


          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.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          • TrvlOrm

            #6
            Ok Thanks

            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 <spam@merlyn.de mon.co.uk> wrote in message news:<WPsJfdCBB mmAFwJU@merlyn. demon.co.uk>...[color=blue]
            > JRS: In article <Xns94E0CFF6C29 18eejj99@194.10 9.133.29>, seen in
            > news:comp.lang. javascript, Evertjan. <exjxw.hannivoo rt@interxnl.net >
            > posted at Wed, 5 May 2004 18:26:36 :[color=green]
            > >
            > >function DrawNumbers( ){
            > > for (var x=1; x<7;x++) {
            > > document.frmNum bers["txtnum"+x].value =
            > > Math.round(Math .random()*100;
            > > }
            > >}
            > >
            > >This should do the same
            > >
            > >not tested[/color]
            >
            >
            > 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.[/color]

            Comment

            Working...