help with typeOf

Results 1 to 2 of 2

Thread: help with typeOf

  1. #1
    Join Date
    Dec 1969

    Default help with typeOf

    OK, trying to do some client side errors checking to make sure users put in the right datatype. In this case, I want users to only put in numeric values.<BR><BR>The function I wrote only returns "string" in the message, even when I put in numeric values. I&#039m rather new to javascrip, so any pointers/alternatives will help.<BR><BR>Here&#039s the function I wrote:<BR><BR>&#060;script language="JavaScript1.1"&#062;<BR>&#060;!--<BR>//a function to test if the value inserted is numeric<BR>function testValue(i){<BR>val = i.value<BR>if (typeof(val) == "string"){<BR>msg = typeof(val)<BR>msg = typeof(val) + " is the value:" + val<BR>alert(msg)<BR>}<BR>}<BR>//--&#062;<BR>&#060;/script&#062;<BR><BR>Here&#039s the input tag:<BR><BR>&#060;input type="text" name="test" value="" onblur="testValue(this)"&#062;<BR><BR>In my initial testing, I did not put the input tag between form tags, but I&#039m not sure it&#039s necessary to get this to work.<BR><BR>Thanks.<BR><BR>Dano

  2. #2
    Join Date
    Dec 1969

    Default RE: help with typeOf

    This will work for numbers, Good Luck!<BR><BR>if (isNaN(document.forms[0].text1.value))<BR>{<BR> alert("This field is not a number!");<BR> document.forms[0].text1.focus();<BR>}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts