SunQuest
 
           JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old April 6th, 2004, 03:55 AM
Love_Storms Love_Storms is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 1 Love_Storms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Using Loops

Ok, how do i explain this? Heres my set up: i have an input box, and a textArea box. I want to create a function that basically demonstrates the power of a loop. To do this, i wanted for a person to basically type a number in an input text field, and then have that number be the thing that is compared for the loops primary conditions, such as for(i=0; i < inputBox.value; i++). How do use a loop in a function that takes one of its comparisons from a text box? Heres what i have for a code:

<script type="text/javascript">

function myLooper()
{
inputBox = document.frmOne.inputBox.value;
displayBox = document.frmOne.displayBox;

var multiplier = inputBox.value;
for (var i = 0; i < inputBox.value; i++){
answer = i * multiplier;
displayBox.value += "I am a loop " + i + answer + "\n";
}
}
</script>


Any ideas on how my goal could be achieved?

Reply With Quote
  #2  
Old April 6th, 2004, 05:40 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Location: Sydney, AU
Posts: 2,058 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 6 m 11 sec
Reputation Power: 8
Send a message via ICQ to stumpy Send a message via MSN to stumpy
For some reason you attempt to get the inputbox value twice, but do it incorrectly the second time.... anyway, I've rewritten it and got it working. I haven't used a text area as it's easier to just print to screen. Feel free to rem the alert line.
Code:
function myLooper() {
	inputBox = document.form1.textfield.value;
	displayBox = document.getElementById("output")
	for (var i = 0; i < inputBox; i++){
		answer = i * inputBox;
		alert(answer)
		displayBox.innerHTML += i + ". " + answer + "<br>";
	}
}
</script>
</head>

<body>
<form name="form1" id="form1" method="post" action="">
	<p>
		<input type="text" name="textfield" />
	</p>
	<p>&nbsp;</p>
	<div id="output"></div>
	<input type="button" onclick="myLooper()">
</form>
</body>
__________________
DevArticles Moderator
BlueSix - Web Development and Consulting

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > Using Loops


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway