Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-16-2012, 04:11 AM   PM User | #1
lynny
New to the CF scene

 
Join Date: Oct 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
lynny is an unknown quantity at this point
Can't see output

I am creating a program with css, html, and javascript. It needs to convert numbers to roman numerals. I can't seem to get any output. Can anyone give me suggestions?
Thanks!

javascript
Code:
Javascript	
	function convert(d) {
	document.getElementById("output").innerText = value;
		
	if (!+d){
		alert('No data was input');
		return '';
		
	var	digits = String(+d).split("");
		key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
		       "","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
		       "","I","II","III","IV","V","VI","VII","VIII","IX"];
		roman = "";
		i = 3;
	
	while (i--)
		roman = (key[+digits.pop() + (i * 10)] || "") + roman;
		
	return Array(+digits.join("") + 1).join("M") + roman;
	}
html
Code:
....other code above
<body>
	<div id="box">
		<form>
			 <p>
			 	CSE 3420.001<br/> 
			 	Program 3 - Javascript Application<br/>
			 	Don Retzlaff donr@unt.edu
			 </p>
		<input type="text" name="digit" id = "nums" value=""/>
		<!--	<input type="submit" name="button" value="Convert to Roman Numerals" -->
			<button onclick="convert(d)">convert to Roman Numerals</button>
		</form>
		<span id="output"></span>
	</div>
	
</body>
.......other code below
lynny is offline   Reply With Quote
Old 10-16-2012, 07:18 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Several problems

1 - You are handing over the variable "d" to the function convert(). Where do you define "d"? Hint: The value is that of a text field document.getElementById('nums').value and could be extracted inside the function with no parameter at all
2 - You are not outputting anything. The only thing you are doing is returning a value. Returning values from an inline event handler generally doesn't make much sense. You should call a method to output the value(s) to the screen (alert() could be something to begin with). The first line document.getElementById("output").innerText = value; doesn't make any sense because you didn't compute any "value" yet
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52 AM.


Advertisement
Log in to turn off these ads.