san1 Posted February 23, 2014 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 Link to comment Share on other sites More sharing options...
Don E Posted February 23, 2014 Share Posted February 23, 2014 When you say phone number phrase, you mean: three one three five five five three two one six? Link to comment Share on other sites More sharing options...
san1 Posted February 23, 2014 Author Share Posted February 23, 2014 If I say "Hello World", it should display the number 43556 96753 Link to comment Share on other sites More sharing options...
Don E Posted February 24, 2014 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 Link to comment Share on other sites More sharing options...
davej Posted February 24, 2014 Share Posted February 24, 2014 If I say "Hello World", it should display the number 43556 96753 How do you say one or zero? Link to comment Share on other sites More sharing options...
san1 Posted February 24, 2014 Author 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. Link to comment Share on other sites More sharing options...
Don E Posted February 24, 2014 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> Link to comment Share on other sites More sharing options...
davej Posted February 26, 2014 Share Posted February 26, 2014 So then I'm curious -- will Siri interface to Javascript? Link to comment Share on other sites More sharing options...
san1 Posted February 26, 2014 Author 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... Link to comment Share on other sites More sharing options...
thescientist Posted February 26, 2014 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. Link to comment Share on other sites More sharing options...
davej Posted February 26, 2014 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. Link to comment Share on other sites More sharing options...
thescientist Posted February 26, 2014 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 26, 2014 Share Posted February 26, 2014 Siri, dial whukblr Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now