I need to split the area code out of the () so it only displays numbers using the substring method. Below is the code I have done so car.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>No Title</title>
<script type = "text/javascript">
<!--
function splitButtonPressed()
{
	var inputString = document.getElementById( "inputVal").value;
	var mySplitResult = inputString.split(" ");
	
	document.getElementByID("area").value = mySplitResult[0].substring(1,3);
	document.getElementById("number").value = mySplitResult[1];	
}
// -->
</script>
</head>

<body>
<h1> Lab Excerise</h1>
<form action = "">
<table width="600" border="2" cellspacing="1" cellpadding="1">
  <tr>
    <td>Enter a phone number [in the form (555) 555-5555] </td>
    <td><input id = "inputVal" type = "text" /></td>
  </tr>
  <tr>
    <td><input type = "button" value = "Split" onclick = "splitButtonPressed()" /> </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td>Area code:</td>
    <td><input id = "area" type = "text" size = "15" /></td>
  </tr>
  <tr>
    <td>Number: </td>
    <td><input id = "number" type = "text" size = "15" /></td>
  </tr>
</table>
</form>


</body>
</html>

The error is in the below line

document.getElementByID("area").value = mySplitResult[0].substring(1,3)

because if i delete the rest after [0] then it prints perfect but displays the () with the area code and that's not what I need.

Thanks.

Are you using FireBug to debug your code? If not you should use. What is the error that you get? "document.getElementByID is not a function" Look much closer to what you wrote. :P

Umh, use regex

inputString = inputString.replace(/[^0-9]/g,'')

hi

i think ...macneato... provide information is best and he solved your problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.