Question

In: Computer Science

I am having a hard time getting my an output after putting in the second set...

I am having a hard time getting my an output after putting in the second set of functions and I was hoping to be able to have the results from the functions be rounded to 2 decimal places.


<html>
<head>
<title>Length Conversion</title>
<script language='JavaScript' type='text/JavaScript'>
<!--
function validate(type) {
if(document.my_form.textinput.value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_feet"){
var res=3.2808*document.my_form.textinput.value;
var unit=" feet";
}else{
var res=0.3048*document.my_form.textinput.value;
var unit=" meter";

}
document.getElementById("result").innerHTML=res.toFixed(2) + unit;
return false;
}
}
function validate1(type) {
       if(document.my_form.textinput.value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_pounds"){
var res=document.my_form1.textinput1.value/2.205;
var unit=" pounds";
}else{
var res=2.205*document.my_form1.textinput.value;
var unit=" kilograms";
}
document.getElementById("result1").innerHTML=res.toFixed(2) + unit;
return false;
}
//-->
</script>
</head>
<body>
<p> This form allows you to convert between different systems , enter the known length and click on the desired conversion.</p>
<form name='my_form' action='' method='post'
onSubmit='return validate();'>
Input :<input type=text name=textinput size=10>
<input type=button value='Convert to Feet' onClick=validate('to_feet');>
<input type=button value='Convert to Meter' onClick=validate('to_meter');>

</form>
<div id=result></div>
<hr>
<p1> This portion will allow you to convert between two different systems of pounds and kilograms. </p1>
<form name='my_form1' action='' method='post'
       onSubmit='return validate1();'>
Input:<input type=text name=textinput1 size=10>
<input type=button value='Convert to Pounds'
onClick=validate1('to_pounds');>
<input type=button value='Convert to Kilograms'
onClick=validate1('to_kilograms');>
</form>
<div1 id=result1></div>


</body>
</html>

Solutions

Expert Solution

deserves thumbs up :)

<html>
<head>
<title>Length Conversion</title>
<script language='JavaScript' type='text/JavaScript'>
function validate(type){
if(document.getElementById("inp1").value=='')
{
alert('Fill the Input box before submitting');
return false;
}
else{
if(type=="to_feet"){
var res=3.2808*parseFloat(document.getElementById("inp1").value);
var unit=" feet";
}else{
var res=0.3048*parseFloat(document.getElementById("inp1").value);
var unit=" meter";

}
document.getElementById("result").innerHTML=res.toFixed(2) + unit;
return false;
}
}
function validate1(type) {
if(document.getElementById("inp2").value=='')
{
alert('Fill the Input box before submitting');
return false;
}else{
if(type=="to_pounds"){
var res=parseFloat(document.getElementById("inp2").value)/2.205;
var unit=" pounds";
}else{
var res=2.205*parseFloat(document.getElementById("inp2").value);
var unit=" kilograms";
}
document.getElementById("result1").innerHTML=res.toFixed(2) + unit;
return false;
}
}
</script>
</head>
<body>
<p> This form allows you to convert between different systems , enter the known length and click on the desired conversion.</p>
<form name='my_form' action='' method='post'
onSubmit='return validate();'>
Input :<input id="inp1" type=text name=textinput size=10>
<input type=button value='Convert to Feet' onClick=validate('to_feet');>
<input type=button value='Convert to Meter' onClick=validate('to_meter');>

</form>
<div id=result></div>
<hr>
<p1> This portion will allow you to convert between two different systems of pounds and kilograms. </p1>
<form name='my_form1' action='' method='post'
onSubmit='return validate1();'>
Input:<input id="inp2" type=text name=textinput1 size=10>
<input type=button value='Convert to Pounds'
onClick=validate1('to_pounds');>
<input type=button value='Convert to Kilograms'
onClick=validate1('to_kilograms');>
</form>
<div1 id=result1></div>


</body>
</html>

 

 

Related Solutions

I am having a hard time getting started on how to do this assignment. I would...
I am having a hard time getting started on how to do this assignment. I would like some ideas on how to start the MEMO. and maybe some ideas on what you would include. But I don't necessarily need the assignment completed for me. just need ideas!!! One routine negative message in the form of an internal memo. 400-500 word message. Single-spaced, with 1-inch margins on all sides. Objective: To announce organizational restructuring, one routine negative message addressed to employees....
For some reason I am having a hard time getting this program to compile properly. Could...
For some reason I am having a hard time getting this program to compile properly. Could you help me debug it? Write the prototypes and functions to overload the given operators in the code //main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() {     rectangleType rectangle1(23, 45);                     //Line 1     rectangleType rectangle2(12, 10);                     //Line 2     rectangleType rectangle3;                             //Line 3     rectangleType rectangle4;                             //Line 4     cout << "Line...
I'm having a very hard time getting this c++ code to work. I have attached my...
I'm having a very hard time getting this c++ code to work. I have attached my code and the instructions. CODE: #include using namespace std; void printWelcome(string movieName, string rating, int startHour, int startMinute, char ampm); //menu function //constants const double TICKET_PRICE = 9.95; const double TAX_RATE = 0.095; const bool AVAILABLE = true; const bool UNAVAILABLE = false; int subTotal,taxAdded, totalCost; // bool checkAvailability( int tickets, int& seatingLeft){ //checks ticket availability while(tickets > 0 || tickets <= 200) //valid...
I am having problems getting the second button part of this to work. this is for...
I am having problems getting the second button part of this to work. this is for visual basic using visual studio 2017. Please help. Create an application named You Do It 4 and save it in the VB2017\Chap07 folder. Add two labels and two buttons to the form. Create a class-level variable named strLetters and initialize it to the first 10 uppercase letters of the alphabet (the letters A through J). The first button’s Click event procedure should use the...
I have the below program and I am having issues putting all the output in one...
I have the below program and I am having issues putting all the output in one line instead of two. how can I transform the program for the user enter format ( HH:MM) Like: Enter time using 24 format ( HH:MM) : " and the user enter format " 14:25 then the program convert. instead of doing two lines make all one line. Currently I have the user enter first the Hour and then the minutes but i'd like to...
I am implementing a generic List class and not getting the expected output. My current output...
I am implementing a generic List class and not getting the expected output. My current output is: [0, 1, null] Expected Output in a separate test class: List list = new SparseList<>(); list.add("0"); list.add("1"); list.add(4, "4"); will result in the following list of size 5: [0, 1, null, null, 4]. list.add(3, "Three"); will result in the following list of size 6: [0, 1, null, Three, null, 4]. list.set(3, "Three"); is going to produce a list of size 5 (unchanged): [0,...
I am implementing a generic List class and not getting the expected output. My current output...
I am implementing a generic List class and not getting the expected output. My current output is: [0, 1, null] Expected Output in a separate test class: List list = new SparseList<>(); list.add("0"); list.add("1"); list.add(4, "4"); will result in the following list of size 5: [0, 1, null, null, 4]. list.add(3, "Three"); will result in the following list of size 6: [0, 1, null, Three, null, 4]. list.set(3, "Three"); is going to produce a list of size 5 (unchanged): [0,...
I understand the answer to this I am just having a hard time creating a graph...
I understand the answer to this I am just having a hard time creating a graph for it. Bill the butcher is upset because the government plans to tax beef $.10 a pound. "I hate paying taxes," he says. "Because of this, I'm raising all my beef prices by $.10 a pound. The consumers will bear this burden, not me." Do you see anything wrong with this way of thinking? Explain. Draw a graph describing your answer and attach it...
Hello, I am having trouble getting started on my project and building these functions. How do...
Hello, I am having trouble getting started on my project and building these functions. How do I build a function that continuously adds new "slices" to the list if they are below/above the size limit? I didn't copy the entire problem, but just for reference, when the code is run it will take user input for size limit (L), time cost for a random slice(R), and time cost for an accurate slice(A). Question: In real life, a steak is a...
can someone explain to me what osmolality is.? i am having a hard time understanding it
can someone explain to me what osmolality is.? i am having a hard time understanding it
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT