Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •