views:

35

answers:

2

from my textbox, i need to get the first digit entered into that, and check whther it is 7 or 8 or 9.. using getelementbyid, how can i get this.... how can check whether first digit is 7 or 8 or 9 in the textbox

A: 

call the script function on onkeypressevent like this

onkeypress="return urfunction(this);"

in function you will get the value like this

function urfunction(obj){var value = obj.value;}
Dilse Naaz
+1  A: 

Add the script below to the "head" section of your html

<script  type="text/javascript">
function validateTextBox()
{
  var input= document.getElementById("textboxid"); 
  if ( input != null)
  {
   //test the input.value here;
   //not sure what you need to do after the test...
  }   
}
</script>

Call the javascript function from an event,say on click event of a button on your page

<input type="button" value="Validate Text" onclick="javascript:validateTextBox()" />
J Angwenyi