check value of text box

Discussion in 'JavaScript' started by Greenmethod, Jul 9, 2009.

  1. #1
    I normally program in php, but I need to check the value of a text box in javascript. I have the following code...

    // JavaScript Document
    function isZip(item)
    {
        var item=item;
        alert(document.frmClaim.item.value);//to verify it has gotten the value
        var str=document.frmClaim.item.value;
        alert("yes");
        if(isNaN(str)){
            alert('That value must be a number.');
            document.frmClaim.item.focus();
            document.frmClaim.item.value = '';
            
        };
    }
    
    ><input type="text" onblur="isZip('insured_zip')" size="7" maxlength="9" name="insured_zip" id="insured_zip" value="<?php echo $_POST['insured_zip']; ?>">
    Code (markup):
     
    Greenmethod, Jul 9, 2009 IP
  2. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    it doesn't alert the yes or the value. I can alert item and it alerts insured_zip. Anyone have any ideas? Thanks!
     
    Greenmethod, Jul 9, 2009 IP
  3. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    and if I replace "item" with insured_zip it works. So basically I need help getting it to use insured_zip as the item.
     
    Greenmethod, Jul 9, 2009 IP
  4. JavaScriptBank.com

    JavaScriptBank.com Peon

    Messages:
    141
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    JavaScriptBank.com, Jul 9, 2009 IP
  5. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #5
    Try this.

    Hope this helps,
     
    Unni krishnan, Jul 9, 2009 IP
  6. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Ok, I got it to check the value, but now I need it to set the focus back to the object if its not a number. I've tried 50 different things with that focus(). Any ideas?
     
    Greenmethod, Jul 10, 2009 IP
  7. Greenmethod

    Greenmethod Peon

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    just tried it in ie and it works fine. not in Mozilla/5.0 browser.
     
    Greenmethod, Jul 10, 2009 IP