5 Replies - 1893 Views - Last Post: 03 October 2012 - 12:04 AM

#1 njgmoorman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 02-October 12

undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 02 October 2012 - 05:48 AM

I'm trying to make a data converter and I'm having an issue (I'm guessing) somewhere in my Javascript. Anyone who can fix this and/or help to shorten it or make it easier to understand would be greatly appreciated.
<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Convert Data</title>
		<style type="text/css">			
				.button {
				-moz-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
				-webkit-box-shadow:inset 0px 1px 0px 0px #bbdaf7;
				box-shadow:inset 0px 1px 0px 0px #bbdaf7;
				background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #79bbff), color-stop(1, #378de5) );
				background:-moz-linear-gradient( center top, #79bbff 5%, #378de5 100% );
				filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#79bbff', endColorstr='#378de5');
				background-color:#79bbff;
				-moz-border-radius:6px;
				-webkit-border-radius:6px;
				border-radius:6px;
				border:1px solid #84bbf3;
				display:inline-block;
				color:#ffffff;
				font-family:arial;
				font-size:15px;
				font-weight:bold;
				padding:6px 24px;
				text-decoration:none;
				text-shadow:1px 1px 0px #528ecc;
			}
			.button:hover {
				background:-webkit-gradient( linear, left top, left bottom, color-stop(0.05, #378de5), color-stop(1, #79bbff) );
				background:-moz-linear-gradient( center top, #378de5 5%, #79bbff 100% );
				filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#378de5', endColorstr='#79bbff');
				background-color:#378de5;
			}
			.button:active {
				position:relative;
				top:1px;
			}
			/* This imageless css button was generated by CSSButtonGenerator.com */
			.outputStyle {
				font-size:20px;
				font-family:sans-serif;
			}
		</style>
	</head>

	<body align="center">
		<!-- <form name="convInputs" id="inputs">
			<label class="outputStyle">Convert:</label>
			<input type="text" name="startNum" id="startingNum">
			<select name="iDropDown" id="select1">
				<option>Select One:</option>				
				<option value="byte">Byte(s)</option>
				<option value="kilobyte">Kilobyte(s)</option>
				<option value="megabyte">Megabyte(s)</option>
				<option value="gigabyte">Gigabyte(s)</option>
				<option value="terabyte">Terabyte(s)</option>
				<option value="petabyte">Petabyte(s)</option>
				<option value="exabyte">Exabyte(s)</option>
				<option value="zettabyte">Zettabyte(s)</option>
				<option value="yottabyte">Yottabyte(s)</option>
			</select>
			<select name="oDropDown" id="select2">
				<option>Select One:</option>				
				<option value="byte">Byte(s)</option>
				<option value="kilobyte">Kilobyte(s)</option>
				<option value="megabyte">Megabyte(s)</option>
				<option value="gigabyte">Gigabyte(s)</option>
				<option value="terabyte">Terabyte(s)</option>
				<option value="petabyte">Petabyte(s)</option>
				<option value="exabyte">Exabyte(s)</option>
				<option value="zettabyte">Zettabyte(s)</option>
				<option value="yottabyte">Yottabyte(s)</option>
			</select>
		</form>
		<div id="conversionOutput">
		</div> -->
		<!-- <script type="text/javascript" >
			function runIt() {				
				function getVal(inputValue) {
					inputValue = document.inputValue.startNum.value;
					alert(inputValue);			
				}
			getVal();
				function getValue1() {
					var val = document.iSelectedValue.iDropDown.value;
					var si = document.iSelectedValue.iDropDown.selectedIndex; 
					if (si != 0) {
						var textval = document.iSelectedValue.iDropDown.options[si].text;
					
						alert (val); // for testing
						alert (textval); // for testing
					}
					alert(val);
				}
			getValue1();
				function getValue2() {
					var val1 = document.oSelectedValue.oDropDown.value;
					var si1 = document.oSelectedValue.oDropDown.selectedIndex; 
					if (si1 != 0) {
						var textval1 = document.oSelectedValue.oDropDown.options[si1].text;
					
						alert (val1); // for testing
						alert (textval1); // for testing
					}
					alert(val1);
				}
			getValue2();
		}
		</script> -->
		<!-- <script type="text/javascript" >
			function convert() {			
				function MakeConversion(input, iDataType, oDataType) {
					this.	input = input;
					this.iDataType = iDataType;
					this.oDataType = oDataType;
				}
				var iP = document.convInputs.startNum.value;
				var iPDT = document.convInputs.iDropDown.value;
				var oPDT = document.convInputs.oDropDown.value;
				var conv = new MakeConversion(iP, iPDT, oPDT);
				alert(conv.iP);
				alert(conv.iPDT);
				alert(conv.oPDT);
			}
		</script> -->
		<script type = "text/javascript">	
				/*var getInput = function(ip) {
					document.getElementById("conversionOutput").innerHTML = ip;
				}
				var getIDT = function(idt) {
					document.getElementById("conversionOutput").innerHTML = idt;
				}
				var getODT = function(odt) {
					document.getElementById("conversionOutput").innerHTML = odt;	
				}*/
				var getInput = function(ip) {
					ip = prompt("What data type are you converting from?");
				}
				var getIDT = function(idt) {
					idt = prompt("Enter the amount of " + inputDataType + "(s) you want to convert:");
				}
				var getODT = function(odt) {
					odt = prompt("What data type are you converting to?");	
				}
			function makeConversion(inp, inpd, opdata) {
				inp = getInput().ip;
				inpd = getIDT().idt
				opdata = getODT().odt;			
			}
			//var conversion = new makeConversion();
			function prepConvert(iP, ipdt, opdt) {
				switch(ipdt) {
					case "byte":
					iP = iP;
					break;
			
					case "kilobyte":
					iP *= 1024;
					break;
		
					case "megabyte":
					iP *= 1048576;
					break;
		
					case "gigabyte":
					iP *= 1073741824;
					break;
		
					case "terabyte":
					iP *= 1099511627776;
					break;
		
					case "petabyte":
					iP *= 1125899906842624;
					break;
		
					case "exabyte":
					iP *= 1152921504606846976;
					break;
		
					case "zettabyte":
					iP *= 1180591620717411303424;
					break;
		
					case "yottabyte":
					iP *= 1208925819614629174706176;
					break;
		
					default: alert("invalid data type");
				}
				this.inputToByte = iP;
			}
			//var preConvert = new prepConvert(conversion.ip, conversion.idt, conversion.odt);
			function convert(oP, iPDT, oPDT) {
				this.oP = preConvert.inputToByte;
				parseFloat(this.oP);
				this.iPDT = conversion.idt;
				this.oPDT = conversion.odt;
				switch(this.oPDT){
					case "byte":
					this.oP = this.oP;
					break;
		
					case "kilobyte":
					this.oP *= 0.000976563;
					break;
		
					case "megabyte":
					this.oP *= 0.00000095367;
					break;
			
					case "gigabyte":
					this.oP *= 0.00000000093132;
					break;
		
					case "terabyte":
					this.oP *= 0.00000000000090949;
					break;
		
					case "petabyte":
					this.oP *= 0.00000000000000088818;
					break;
		
					case "exabyte":
					this.oP *= 0.000000000000000000867361738;
					break;
		
					case "zettabyte":
					this.oP *= 0.000000000000000000000847032947;
					break;
		
					case "yottabyte":
					this.oP *= 0.000000000000000000000000827180613;
					break;
		
					default: alert("invalid data type");
				}
			}
			//var finalConv = new convert();
			function writeOutput() {
				var line = conversion.ip + " " + conversion.idt + "(s) is " + finalConv.oP + " " + conversion.odt + "(s).";
				var p = document.createElement("p");
				p.className = "outputStyle";
				p.id = "convOut"
				p.innerHTML = line;
				document.getElementById("conversionOutput").appendChild(p);
			}
		</script>
		
		<form name="convInputs" id="inputs">
			<label class="outputStyle">Convert:</label>
			<input type="text" name="startNum" id="startingNum">
			<select name="iDropDown" id="select1">
				<option>Select One:</option>				
				<option value="byte">Byte(s)</option>
				<option value="kilobyte">Kilobyte(s)</option>
				<option value="megabyte">Megabyte(s)</option>
				<option value="gigabyte">Gigabyte(s)</option>
				<option value="terabyte">Terabyte(s)</option>
				<option value="petabyte">Petabyte(s)</option>
				<option value="exabyte">Exabyte(s)</option>
				<option value="zettabyte">Zettabyte(s)</option>
				<option value="yottabyte">Yottabyte(s)</option>
			</select>
			<select name="oDropDown" id="select2">
				<option>Select One:</option>				
				<option value="byte">Byte(s)</option>
				<option value="kilobyte">Kilobyte(s)</option>
				<option value="megabyte">Megabyte(s)</option>
				<option value="gigabyte">Gigabyte(s)</option>
				<option value="terabyte">Terabyte(s)</option>
				<option value="petabyte">Petabyte(s)</option>
				<option value="exabyte">Exabyte(s)</option>
				<option value="zettabyte">Zettabyte(s)</option>
				<option value="yottabyte">Yottabyte(s)</option>
			</select>
		</form>
		<div id="conversionOutput">
		</div>

		<!-- <input type = "text" id = "txt" onblur = "doIt(this.value)"> -->
		<br>
		<br>
		<br>
		<a href="javascript:var conversion = new makeConversion();var preConvert = new prepConvert(conversion.ip, conversion.idt, conversion.odt);var finalConv = new convert();writeOutput();" class="button">Convert</a>
	</body>
</html>


Is This A Good Question/Topic? 0
  • +

Replies To: undefined undefined(s) is undefined undefined(s). Data Converter issue

#2 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 02 October 2012 - 05:56 AM

it would be incredibly helpful if you could describe your issue. what does it do it shouldn’t (and vice versa)?

a look into the Error Console may also help.

PS. I’d probably hook into the option values, why not providing the factor there? (mental note: got it working in 15 lines)

This post has been edited by Dormilich: 02 October 2012 - 06:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 njgmoorman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 02-October 12

Re: undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 02 October 2012 - 09:21 AM

View PostDormilich, on 02 October 2012 - 05:56 AM, said:

it would be incredibly helpful if you could describe your issue. what does it do it shouldn’t (and vice versa)?

a look into the Error Console may also help.

PS. I’d probably hook into the option values, why not providing the factor there? (mental note: got it working in 15 lines)

I actually don't have an error console. What I want it to do is take the number entered into the input is saved into a variable and multiplied depending on the choices in the drop downs.

then I want the result of that to be printed between the form and the button.

I also want the user to be able to continue making conversions and have each new one printed directly below the first.

sorry I'm so stupid. I'm kind of new at this.

would you mind sharing your 15 line code?

This post has been edited by Dormilich: 02 October 2012 - 09:35 AM

Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 02 October 2012 - 09:41 AM

View Postnjgmoorman, on 02 October 2012 - 06:21 PM, said:

I actually don't have an error console.

you’re not using a browser?


View Postnjgmoorman, on 02 October 2012 - 06:21 PM, said:

would you mind sharing your 15 line code?

I would go as far as sharing the one line that does all the calculation. the remaining 14 lines are just for read/write and such.
// from -  index of the convert_from dropdown
// to - index of the convert_to dropdown
// indices are 0 (B)/>, 1 (KB), 2 (MB), 3 (GB), etc.

Math.pow(1024, from - to) * value;

Was This Post Helpful? 0
  • +
  • -

#5 njgmoorman  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 65
  • Joined: 02-October 12

Re: undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 02 October 2012 - 11:08 AM

Would you care to describe how you assigned the input box and drop down lists to a js variable?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich  Icon User is online

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,236
  • Joined: 08-June 10

Re: undefined undefined(s) is undefined undefined(s). Data Converter issue

Posted 03 October 2012 - 12:04 AM

as you would always do, via the element’s value property.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1