473,657 Members | 2,358 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Issue with [object HTMLInputElemen t] appearing in output box.

14 New Member
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 HTMLInputElemen t] 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 13718
Dormilich
8,658 Recognized Expert Moderator Expert
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 New Member
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 New Member
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 Recognized Expert Moderator Expert
glad you got it sorted.

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

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

Similar topics

1
431
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 it and click. ******************************** HTMLDocument myDoc = new TMLDocumentClass(); myDoc = (HTMLDocument) axWebBrowser1.Document;
2
1555
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 copied elements appear with an empty default namespace appearing on them (xmlns=""). The root element of the output XML does declare a default namespace (xmlns="urn:schemas-microsoft-com:office:spreadsheet").
8
7828
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 the other hand, debugging with breakpoints, etc. seems to work fine in VS.NET 2003. I can't understand why this isn't working -- and I think it used to work, perhaps under VS.NET 2002, but maybe not. The information doesn't appear in exceptions...
0
3218
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: //<input type="text" name="id" id="gmx_email" class="m" accesskey="l" /> HTMLInputElement otxtSearchBox1 = (HTMLInputElement) myDoc.all.item("id", 0);
5
1724
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 you need to run it more than once, and I get those as well, but none are working for me. Here's a mockup of what I have: index.php info.php lib/common.php
28
2117
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 apparently don't fully understand what "this" refers to. In the code below I was expecting that when the button was clicked (handleDeleteButtonClicked function) that "this" would be pointing at a ViewController object. Instead it was the Button...
10
6331
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 so that the window for the Console application is not visible. However, when using some of the 'advanced' properties of the StartInfo object, like Username, Password and Domain, the WindowsStyle property of the StartInfo object is ignored....
5
6706
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 heights are not showing the object properly how to fix... If I increase the height parameter then the page is not appearing properly in IE6
3
12429
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: ====================== Message: Specified cast is not valid. Type: System.InvalidCastException Source: System.Data.Linq TargetSite: Boolean TryCreateKeyFromValues(System.Object, V ByRef)
0
8411
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8323
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8739
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8513
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8613
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7351
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2740
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1732
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.