Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 6th, 2004, 03:14 PM
Registered User
 
Join Date: Dec 2004
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to starsailor
Default random generator

seem to be having some trouble with this code
doesnt seem to want to print

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>sinky online assesement</title>
<link href="style1.css" rel="stylesheet" type="text/css">

<script language="javascript">
    function generate()
    {



    return(Math.floor(Math.random()*(num1-num2+1)))+num1;





    }
</script>
</head>

<body onLoad="resizeTo(800,600)">
<div id="menu">
  <table cellpadding="0" cellspacing="0">
    <tr>
      <th valign="top">Main Menu</th>
    </tr>
    <tr>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr align="left"><td><a href="index.htm" class="mainlevel">Home</a></td></tr>
          <tr align="left"><td><a href="rannum.htm" class="mainlevel">Number Generator</a></td></tr>
          <tr align="left"><td><a href="manipulation.htm" class="mainlevel">Image Manipulation</a></td></tr>
          <tr align="left"><td><a href="sampler.htm" class="mainlevel">Background Colour</a></td></tr>
        </table>
    <img src="images/candle.gif">
      </td>
    </tr>
  </table>
</div>
<div id="header">Number Generator</div>
<div id="main">
    This program will generate a ramdom number within centain perameters.<br />
    Please enter the parameters.<br><br />

        Upper Bound <input type="text" name="num1" id="num1" size="10">
        Lower Bound <input type="text" name="num2" id="num2" size="10"><br><br><br />
        Result <input type="text" name="nresult" size="10" id="nresult"><br><br><br />
    <input type=button value="Generate Random Number" onClick=nresult.innnerhtml="generate()">heelo


  <br><br />Site Author<a href="Dunfermline AFC are Gods"><i> John Scott Sinclair</i></a>
</div>
</body>
</html>


can anybody help

 
Old December 7th, 2004, 12:16 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 642
Thanks: 0
Thanked 43 Times in 42 Posts
Default

Try the following code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>sinky online assesement</title>
<link href="style1.css" rel="stylesheet" type="text/css">

<script language="javascript">
    function generate()
    {

    num1 = form1.num1.value
    num2 = form1.num2.value
    return(Math.floor(Math.random()*(num1-num2+1)))+num1;


    }
</script>
</head>

<body onLoad="resizeTo(800,600)">
<form name=form1>
<div id="menu">
  <table cellpadding="0" cellspacing="0">
    <tr>
      <th valign="top">Main Menu</th>
    </tr>
    <tr>
      <td>
        <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr align="left"><td><a href="index.htm" class="mainlevel">Home</a></td></tr>
          <tr align="left"><td><a href="rannum.htm" class="mainlevel">Number Generator</a></td></tr>
          <tr align="left"><td><a href="manipulation.htm" class="mainlevel">Image Manipulation</a></td></tr>
          <tr align="left"><td><a href="sampler.htm" class="mainlevel">Background Colour</a></td></tr>
        </table>
    <img src="images/candle.gif">
      </td>
    </tr>
  </table>
</div>
<div id="header">Number Generator</div>
<div id="main">
    This program will generate a ramdom number within centain perameters.<br />
    Please enter the parameters.<br><br />

        Upper Bound <input type="text" name="num1" id="num1" size="10">
        Lower Bound <input type="text" name="num2" id="num2" size="10"><br><br><br />
        Result <input type="text" name="nresult" size="10" id="nresult"><br><br><br />
    <input type=button value="Generate Random Number" onClick=nresult.value=generate();>heelo


  <br><br />Site Author<a href="Dunfermline AFC are Gods"><i> John Scott Sinclair</i></a>
</div>
</form>
</body>
</html>

-------------------------
Also, there is no form tag in the code, and the variables num2 and num1 is not populated.

Please check the following link for random number code:

http://javascript.internet.com/misce...r-numbers.html



Om Prakash





Similar Threads
Thread Thread Starter Forum Replies Last Post
Flixon Site Generator jimibt BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 February 14th, 2008 11:33 AM
Product code generator yogeshyl Excel VBA 1 October 3rd, 2007 10:50 AM
Code generator and some other things Hyzac BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 13 October 9th, 2006 02:06 PM
Number Sequence Generator Peso SQL Server 2000 4 May 11th, 2006 01:36 PM
Random Numbers not so random... katsarosj ASP.NET 1.0 and 1.1 Basics 5 November 20th, 2003 12:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.