san1 0 Posted February 23, 2014 Report Share Posted February 23, 2014 I'm required to- ask the user for the phone number phrase using a standard HTML form and followed by a- java script function to convert the number phrase into actual number- the final output must show up without using html input controlsBeen trying to accomplish this using if else statements within the <script> tag but did not succeed.Any help would be greatly appreciated.Thanks Quote Link to post Share on other sites
Don E 125 Posted February 23, 2014 Report Share Posted February 23, 2014 When you say phone number phrase, you mean: three one three five five five three two one six? Quote Link to post Share on other sites
san1 0 Posted February 23, 2014 Author Report Share Posted February 23, 2014 If I say "Hello World", it should display the number 43556 96753 Quote Link to post Share on other sites
Don E 125 Posted February 24, 2014 Report Share Posted February 24, 2014 (edited) The following is an example of what immediately came to mind in trying to accomplish what you're asking. I'm sure there are other ways as well and you don't have to use a form either. Hopefully it will give you an idea that sets you in the right direction. <!doctype html><html><head><meta charset="UTF-8"><title>Phone Number Phrase</title> <script type="text/javascript"> function checkPhrase(form) { var number = ''; var phrase = form.phrase.value; for(var i = 0; i < phrase.length; i++) { switch(phrase[i]) { case 'a': case 'b': case 'c': number = number + '2'; break; case 'd': case 'e': case 'f': number = number + '3'; break; case 'g': case 'h': case 'i': number = number + '4'; break; case 'j': case 'k': case 'l': number = number + '5'; break; case 'm': case 'n': case 'o': number = number + '6'; break; case 'p': case 'q': case 'r': case 's': number = number + '7'; break; case 't': case 'u': case 'v': number = number + '8'; break; case 'w': case 'x': case 'y': case 'z': number = number + '9'; break; } } alert(number); return false; } </script></head><body><form method="post" action="#" onSubmit="return checkPhrase(this)"><label>Enter phrase number:</label><input type="text" name="phrase" size="10"/><br/><input type="submit" name="submit" /></form></body></html> Edited February 24, 2014 by Don E 1 Quote Link to post Share on other sites
davej 251 Posted February 24, 2014 Report Share Posted February 24, 2014 If I say "Hello World", it should display the number 43556 96753 Â How do you say one or zero? Quote Link to post Share on other sites
san1 0 Posted February 24, 2014 Author Report Share Posted February 24, 2014 Thanks that worked!  Also, I would need to have the text in the button to change depending on the input in the text area. If I say "Hello World" and if the button says Submit is ....., it should display "Submit is Hello World". I used the following code <button type="text" onclick="checkPhrase(form)"> code to accomplish but it did not happen  Also i would need the final output on the same page in the form area and not as a separate window. I used "document.write" instead of alert but the output was showing up in a new page. Quote Link to post Share on other sites
Don E 125 Posted February 24, 2014 Report Share Posted February 24, 2014 Here's updated code based on what you mentioned. I commented out certain parts from the previous code. <!doctype html><html><head><meta charset="UTF-8"><title>Phone Number Phrase</title> <script type="text/javascript"> function checkPhrase(/*form*/) { var number = ''; //var phrase = form.phrase.value; var phrase = document.getElementById('numPhrase').value; for(var i = 0; i < phrase.length; i++) { switch(phrase[i]) { case 'a': case 'b': case 'c': number = number + '2'; break; case 'd': case 'e': case 'f': number = number + '3'; break; case 'g': case 'h': case 'i': number = number + '4'; break; case 'j': case 'k': case 'l': number = number + '5'; break; case 'm': case 'n': case 'o': number = number + '6'; break; case 'p': case 'q': case 'r': case 's': number = number + '7'; break; case 't': case 'u': case 'v': number = number + '8'; break; case 'w': case 'x': case 'y': case 'z': number = number + '9'; break; } } document.getElementById('numPhrBut').innerHTML = "Submit is: " + phrase; document.getElementById('dispNum').innerHTML = "Phrase converted is: " + number; //alert(number); //return false; } </script></head><body><label>Enter phrase number:</label><input id="numPhrase" type="text" name="phrase" size="10"/><br/><button id="numPhrBut" type="button" onClick="checkPhrase()">Submit</button><br/><span id="dispNum"></span><!--<form method="post" action="#" onSubmit="return checkPhrase(this)"><label>Enter phrase number:</label><input type="text" name="phrase" size="10"/><br/><input type="submit" name="submit" /></form> --></body></html> Quote Link to post Share on other sites
davej 251 Posted February 26, 2014 Report Share Posted February 26, 2014 So then I'm curious -- will Siri interface to Javascript? Quote Link to post Share on other sites
san1 0 Posted February 26, 2014 Author Report Share Posted February 26, 2014 Â The following is an example of what immediately came to mind in trying to accomplish what you're asking. I'm sure there are other ways as well and you don't have to use a form either. Hopefully it will give you an idea that sets you in the right direction. <!doctype html><html><head><meta charset="UTF-8"><title>Phone Number Phrase</title> <script type="text/javascript"> function checkPhrase(form) { var number = ''; var phrase = form.phrase.value; for(var i = 0; i < phrase.length; i++) { switch(phrase[i]) { case 'a': case 'b': case 'c': number = number + '2'; break; case 'd': case 'e': case 'f': number = number + '3'; break; case 'g': case 'h': case 'i': number = number + '4'; break; case 'j': case 'k': case 'l': number = number + '5'; break; case 'm': case 'n': case 'o': number = number + '6'; break; case 'p': case 'q': case 'r': case 's': number = number + '7'; break; case 't': case 'u': case 'v': number = number + '8'; break; case 'w': case 'x': case 'y': case 'z': number = number + '9'; break; } } alert(number); return false; } </script></head><body><form method="post" action="#" onSubmit="return checkPhrase(this)"><label>Enter phrase number:</label><input type="text" name="phrase" size="10"/><br/><input type="submit" name="submit" /></form></body></html> That was very elaborate and helpful! Thank you for taking the time... Quote Link to post Share on other sites
thescientist 231 Posted February 26, 2014 Report Share Posted February 26, 2014 So then I'm curious -- will Siri interface to Javascript? in what way? Javascript run in a browser typically, Siri runs on the iOS platform itself. Quote Link to post Share on other sites
davej 251 Posted February 26, 2014 Report Share Posted February 26, 2014 If I say "Hello World", it should display the number 43556 96753 Â I thought maybe this was Siri-related voice recognition. Quote Link to post Share on other sites
thescientist 231 Posted February 26, 2014 Report Share Posted February 26, 2014 Ah, I getcha. Not sure, usually Sire responds to prompts and keywords. Not sure if it could handle filling out an online form on a webpage. Quote Link to post Share on other sites
justsomeguy 1,135 Posted February 26, 2014 Report Share Posted February 26, 2014 Siri, dial whukblr Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.