473,385 Members | 2,162 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,385 software developers and data experts.

Issue with [object HTMLInputElement] appearing in output box.

14
Hey there, Just wanted to say Hi. - I'm new on here & have drifted here as I'm having a minor problem I was hoping someone could assist ...?
(for some reason I couldn't post this directly into the Javascript forum, don't seem to have a 'New Thread' button)

Am working on a 'lottery drawing program' for an assignment, so far have coded the below, but for some reason, on the output page, it keeps putting

[object HTMLInputElement] into the output Text box.. - any ideas?

Many thanks in advance, - AB.


Expand|Select|Wrap|Line Numbers
  1. <HTML>
  2. <HEAD>
  3. <TITLE>Programming : Task - Drawing numbered balls</TITLE>
  4.  
  5. <SCRIPT language="JavaScript">
  6.  
  7.      // My  getRandomNumber function
  8.         function getRandomNumber (myNum)
  9.         {
  10.             var getRandomNumber = Math.floor(Math.random() * myNum);
  11.  
  12.             // this returns the number into the alert box.
  13.             return getRandomNumber;
  14.         }            
  15.  
  16.  
  17.     function lotteryDraw(highBall, numberToDraw)
  18.     {
  19.         // This sets up an array called 'numberPool' which will hold your numbers to draw from
  20.         // the arrays size is set to the same as the user's input 'highBall'
  21.         var numberPool = new Array(highBall);
  22.  
  23.         // This is user entered, it sets a variable called sizeOfPool to = the user inputted 'highball'
  24.         var sizeOfPool = highBall;
  25.  
  26.         // once the user enters the amount of numbers they wish to draw it sets up an array to hold them once they have been drawn.
  27.         var drawnNumbers = new Array(numberToDraw);
  28.  
  29.         /*  This is a 'FOR' loop, a loop which iterates a predetermined number of times.
  30.             That number is the same as  the initially entered 'highBall' The loop goes through the spaces in the array  numberPool placing 
  31.             incremented numbers into it's spaces ( 1, 2, 3, 4, etc...) it continues this until it reaches the number that = highBall
  32.             (as the array numberPool is equal to highBall, this means that  every space in the array has a number assigned to it.
  33.         */
  34.         for (var index = 0; index < highBall; index = index + 1)
  35.         {
  36.             numberPool[index] = index + 1; 
  37.         }
  38.  
  39.         /*  This is a FOR loop which iterates a predetremined number of times.
  40.             The number of iterations is governed by the number that the user enters as  the number of balls they wish to draw (numberToDraw)
  41.             it randomises a number then goes through our array of numbers taking the selected number and placing it into another array ready to display. 
  42.             It also then removes that number from our main list of numbers to make sure that the same number isn't drawn twice'
  43.         */
  44.         for (var drawnBall = 0; drawnBall < numberToDraw; drawnBall = drawnBall + 1)
  45.         {
  46.         // This line creates our random number between 0 & our highest possible number (sizeOfPool)
  47.             var randomNumber = getRandomNumber(sizeOfPool);
  48.         // This line adds our chosden number into the initially blank array 'Drawn Numbers'
  49.         // as this loop runs through, the array will slowly fill up, until all the numbers have been selected
  50.             drawnNumbers[drawnBall] = numberPool[randomNumber];
  51.  
  52.         // This takes our very highest number in our 'numberPool' and copies it over the number that was just selected
  53.         // the reason for this is so that in a minute , when the number of possible selections is shrunk by 1, the only number that is 'dropped out' is
  54.         // The number that was just selected and added to the array 'DrawnNumbers'
  55.             numberPool[randomNumber] = numberPool[sizeOfPool - 1];
  56.  
  57.         // this stops the selection process from selecting the highest number each time 
  58.         // as the highest number each time is written over the number just selected
  59.         // it ensures a full list of numbers that are all uniqwue and are no duplicates of the ones already selected.
  60.             sizeOfPool = sizeOfPool - 1;
  61.         }
  62.         // This writes out the contents of the array  'drawnNumbers' into the space on the HTML form.
  63.         document.lotteryForm.drawnNumbersTextBox.value = drawnNumbers;
  64.       }
  65.  
  66.  
  67.  
  68. </SCRIPT>
  69. </HEAD>
  70. <BODY>
  71.  
  72.     <STRONG>A test of the function lotteryDraw()<BR></STRONG>
  73.     <FORM NAME = "lotteryForm">
  74.     <P>
  75.     Total Number of Balls in Pool:
  76.     </P>
  77.     <P>
  78.     <INPUT TYPE = "text" NAME = "numberOfBallsTextBox"  SIZE ="2" MAXLENGTH = "2">
  79.     </P>
  80.     <P>
  81.     Number of Balls to Draw:
  82.     </P>
  83.     <P>
  84.     <!-- Note the SIZE attribute, whose value determines the size in characters of a text box and
  85.     the MAXLENGTH attribute, whose value constrains the length in characters of the allowed input -->
  86.     <INPUT TYPE = "text" NAME = "ballsToDrawTextBox" SIZE = "1" MAXLENGTH = "1" >
  87.     </P>
  88.  
  89.  
  90.     <!-- The RESET input type creates a button which, when clicked, resets a form to its original state -->
  91.     <INPUT TYPE = "reset" NAME = "resetButton" VALUE = "Clear Form">
  92.  
  93.     <!-- COMPLETE THE ONCLICK EVENT HANDLER TO INVOKE lotteryDraw() WITH ARGUMENTS TAKEN FROM THE FORM INPUT TEXT BOXES -->
  94.     <INPUT TYPE = "button" NAME = "drawBalls"  VALUE ="Draw the Balls!"
  95.                         ONCLICK = "highBall = document.lotteryForm.numberOfBallsTextBox;
  96.                         numberToDraw = document.lotteryForm.ballsToDrawTextBox;
  97.                         lotteryDraw(highBall, numberToDraw);">
  98.  
  99.     <P>
  100.     Drawn Numbers:
  101.     </P>
  102.     <P>
  103.     <INPUT TYPE = "text" NAME = "drawnNumbersTextBox" SIZE = "30" MAXLENGTH = "30" >
  104.     </P>
  105.  
  106.     </FORM>
  107.  
  108. </BODY>
  109. </HTML>
  110.  
May 16 '09 #1
5 13683
Dormilich
8,658 Expert Mod 8TB
your main problems are the input values of lotteryDraw(), these should be integers/strings but they are actually the input elements. therefore the for loop is completely skipped and the output contains the element(s) present in the array.

tip: with the Firebug addon (Firefox) you can go step by step through your code and see, what the values are.
May 17 '09 #2
AB3004
14
Hmm, - OK, I think I get what you mean, I'll have a crack at solving it & let you know how I get on,..

thanks for the guidance.
May 17 '09 #3
AB3004
14
Thank you very much to Dormilich for helping me out.
I'm still learning JS & hadn't used many object outputs etc.

I have now got it working so am very grateful. (on to the next one <sigh>)
May 18 '09 #4
Dormilich
8,658 Expert Mod 8TB
glad you got it sorted.

PS: wait ’til you discover, that everything in Javascript is an object…
May 18 '09 #5
AB3004
14
@Dormilich
Perfect,... Just Perfect.
May 18 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: nsrajesh via DotNetMonster.com | last post by:
Hi I need an immediate help from you guys. I am doing a project, that automate the web browser control. It has to fill some text fields and click a submit button. I use the below code tho fill...
2
by: Simon_Keep | last post by:
Hi, I have an Xslt extension object that returns a node-set to the xslt stylesheet which then uses an xsl:copy-to statement to write it to the output. The problem I am having is that the...
8
by: Arun Bhalla | last post by:
Hi, I'm developing an Explorer bar using VS.NET 2003 (C#) on Windows XP. For some time, I've noticed that I don't have filenames and line numbers appearing in my exceptions' stack traces. On...
0
by: Tom Grinnert | last post by:
Hello, I try to create an automatic login for the gmx email web page (http://www.gmx.net/de/dienst/). Unfortunally the Button for login in has no Id and no name in the HTML Dokument: ...
5
by: paladin.rithe | last post by:
I'm running into an issue with session_start(). I see that you can't run it twice, otherwise it causes an issue. That's fine, and makes sense. I also saw some ideas on how to get around this if...
28
by: ensemble | last post by:
I'm trying to utilized a more object-oriented approach to managing window events in javascript. Thus, I am creating a "controller" object to handle events and interact with the server. However, I...
10
by: Stephany Young | last post by:
When one uses the System.Diagnostics.Process.Start method to launch a common or garden Console application, one can set the WindowStyle property of the StartInfo object to ProcessWindowStyle.Hidden...
5
by: MSK | last post by:
Hi, I am a newbie to CSS , I have an issue in my project its java based web app, all the pages are looking fine IE6,Firebox...but the problem is appearing in IE7 basically some div class...
3
by: =?Utf-8?B?UGF1bCBQcmV3ZXR0?= | last post by:
I'm attempting to use LINQ to insert a record into a child table and I'm receiving a "Specified cast is not valid" error that has something to do w/ the keys involved. The stack trace is: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.