I have a textbox.

in js code, i try this...

if(isNAN(parseInt(form.myTextBox.value))) {alert("not a number");}

I'm trying to check if it is a number. Else i want to warn him....

How can i do this in a js file?

In js file I would advise you to put your code inside a function and the call it with one of the many javascript events

function CheckNumber()
alert('not a number');

Here's Another example:


var checknum = function( form ) {
var val = form.num.value; // Get the UI value.

var typ = (( isNaN( val ) ) ?  val + " is a string." : val + " is a number." ); // Defines the type of UI value.

   alert( typ ); // Alert type of input value.

      return false; // Exit Function and Prevent the form submission.



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html id="html40L" lang="en">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Live Help!</title>
<script id="script15" type="text/javascript" src="checknum.js"></script>
<form id="frm" name="frm" action="#"  onsubmit="return checknum( this )">
<label for="num">Check Number: <input type="text" id="num" name="num" value="" size="10"></label>
<div id="info"></div>
<input id="sbm" name="sbm" type="submit" value="Submit Form">
This question has already been answered. Start a new discussion instead.