...

View Full Version : a statement to output the reformated number to the form



helen11
12-15-2011, 12:22 PM
Hi does anyone know how to output a reformated number to a form?? This is what I have so far:


if (!document.userSurvey.phone.value)
{
alert("Phone number missing. Please enter a valid phone number to continue.");
document.userSurvey.phone.focus();
return false;
}
else
{
var numbersOnly = "";
var chars = "";
var phoneNo = document.userSurvey.phone.value;

for (i = 0; i < phoneNo.length; i++)
{
chars = phoneNo.substring(i,i+1);

if (chars >= "0" && chars <= "9")
{
numbersOnly = numbersOnly + chars;
}
}

if (numbersOnly.length != 13)
{
alert("Incorrect phone number format.You must enter 13 numbers.");
document.userSurvey.focus();
return false;
}
else
{
var areacode = numbers.substring(0,2);
var leading0 = numbersOnly.substring(2,3);
var exchange = numbersOnly.substring(3,5);
var ext1 = numbersOnly.substring(5,9);
var ext2 = numbersOnly.substring(9);
var newNumber =( "+" + areacode + " " +"(" + leading0 + ")" + exchange + " " + ext1 + "-" + ext2);

Philip M
12-15-2011, 12:35 PM
document.userSurvey.phone.value = reformattedNumber;


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

helen11
12-15-2011, 12:42 PM
Do you know a statement to output userName, email, phoneNo, and book choice to the survey textarea?

Philip M
12-15-2011, 12:57 PM
Rather than write the data to a <textarea> you might prefer to put it in a <div>. A newline in a textarea is \n, a newline in a div is <br>



<textarea id ="txtarea1" rows = "6" cols = "30"></textarea>
<br>
<div id = "div1"></div>
<script type = "text/javascript">

var userName= "Mickey Mouse";
var email = "Mickey@nowhere.com";
var phone = "123-456-7890";
var book = "Karma Sutra";

var combined = userName + "\n" + email + "\n" + phone + "\n" + book + "\n";
document.getElementById("txtarea1").value = combined;
var combined2 = userName + "<br>" + email + "<br>"+ phone + "<br>" + book + "<br>";
document.getElementById("div1").innerHTML = combined2;
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum