Jump to content

Desperately needing a help to fix my script please


oavs

Recommended Posts

Hi

I have a script does two things.
1. It selects typed words and displays as capitalise.
2. It also display the typed word in its corresponding numerical configuration as per 'phone keypad' (eg regular phone key pad 2=abc, 3=def etc. etc. )

IT is all working BUT I need to make some changes and I can not get it to work. I would really appreciate if someone give me a working example as I am very new to js. Many thanks in advance Smile

For example I want users to be able to enter dashes, spaces and numeral (- and 0-9) up to maximum 13 digits and characters long including the dashes. So they could enter PHONE-2BANK or PHONE-2-BANKS or 2-PHONE or PHONE BANK

AND as results I want to display as one of the following(depending on what has been entered):In the numbers only section I want to trim and only diplay the first 7 digits.

Entered: PHONE-2BANK PHONE-2-BANKS 2-PHONE PHONE BANK
Results : PHONE-2BANK PHONE-2-BANKS 2-PHONE PHONE BANK(note space between the two words)
74663-2 74663-2-2 2-74663 74663 22



<script type="text/javascript" language="JavaScript">
<!--

function phonewordForm()
{
var Phoneword = document.getElementById("Phoneword").value;
var box = document.wonder.prefix;
var pref = box.options[box.selectedIndex].text;
Phoneword = Phoneword.toLowerCase();

// Clean the Phoneword, remove anything that isnt a alpha.
var filterPhoneword = "";
for(var i = 0; i < Phoneword.length; i++)
{
var alpha = Phoneword.charAt(i);

if(alpha >= "a" && alpha <= "z")
filterPhoneword += alpha;
}

// Check if the Phoneword is of correct character length.
if(filterPhoneword.length > 13 || filterPhoneword.length < 4)
alert("Type between 4 - 13 alphabetic characters, not numbers.\n Example: FLOWERS, PETCARE, FINANCE etc. ");
else
{
document.getElementById("FormResults").style.display = "block";

var number = getNumber(Phoneword);
var bigPhoneWordString = pref + " " + filterPhoneword;
document.getElementById("boldPhoneword").innerHTML = bigPhoneWordString.toUpperCase();
document.getElementById("numberPhoneword").innerHTML = " " +"(" + number + ")";

// Inactivate form above.
document.getElementById("Phoneword").disabled = true;
document.getElementById("prefix").disabled = true;
document.getElementById("demo").disabled = true;
document.getElementById("preferred_Phoneword").value = document.getElementById("Phoneword").value;
document.getElementById("form_prefix").value = pref;
}

return false;
}

function getNumber(Phoneword)
{
var numberString = "";

for(var i = 0; i < Phoneword.length; i++)
{
var alpha = Phoneword.charAt(i);

if(alpha >= "a" && alpha <= "c")numberString += 2 ;
else if(alpha >= "d" && alpha <= "f")numberString += 3;
else if(alpha >= "g" && alpha <= "i")numberString += 4;
else if(alpha >= "j" && alpha <= "l")numberString += 5;
else if(alpha >= "m" && alpha <= "o")numberString += 6;
else if(alpha >= "p" && alpha <= "s")numberString += 7;
else if(alpha >= "t" && alpha <= "v")numberString += 8;
else if(alpha >= "w" && alpha <= "z")numberString += 9;
}

return numberString;
}

function noSubmit()
{
return phonewordForm();
}

-->
</script>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.