0

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.

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by edith135
0

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

Edited by hertze_bogdan: n/a

0

hi

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.