0

I was wondering if anyone could show me how to take a string that is entered and then find that string and use it as my unit of measure . I also have to find a number that is part of a string. for example: How many feet in an 24 inches? If you could point me to a good tutorial I have been looking at several today and they have lead here stuck. I just need a push in the right direction. This is a begginer program and so what you see is what you get.

<html>
 <head>
 <title>Metric Conversion </title>
 <script  type='text/JavaScript'>
 <!--
function convert() {
var input=document.getElementById("input")
 if(document.form.textinput.value=='')
 {
 alert('Please enter a valid unit of measure');
 return false;
 } else {
 if(form=="feet"){
 var res=3.2808*document.form.input.value;
 var unit=" meters";
 }else{
  if(form=="inches")
 var res=0.3048*document.form.input.value;
 var unit=" meters";




 }



 return false;
 }
 }
 //-->
 </script>
 </head>
 <body>
 <form id = "myForm" action = "">
   <p>
   <h1><span style="padding-left: 500px; text-shadow: 8px 8px 8px #FF0000; font-size: 46px;"> Metric Conversions</span></h1>
   </p>
   <p><span style="font-size: 14px; color: #F00;">Please enter the unit you would like converted into metrics:</span>
   <input name = "input" type = "text" placeholder="How many inches are in 2 meters" size = 
"150" />
   <input type = "button" value = "Convert" 
    onclick = "convert()" />
   </p>
 </form>
 <div id=result></div>
 </body>
 </html> 
2
Contributors
1
Reply
15
Views
3 Years
Discussion Span
Last Post by DavidB
0

Does it have to be done like this?

If you have to input a string and then extract the individual words and numbers from it, that would involve regular expressions and can get complicated.

An easier way might be to use
i) a radio button, and ask the user to indicate if the input represents inches or feet, and
ii) a simple text box to accept input of the actual number. Then you just have to use parseFloat on the input, assign it to a variable, and then manipulate that variable as you like.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.