Form Processing Problem

Discussion in 'JavaScript' started by ebusinesscenter, Jan 1, 2008.

  1. #1
    Hi
    I have a form that use a js file to validate form fields. One of this fileld is a number that must be five multilple , but this error for even number that are five multiple such 55.
    This is my code:
    
    var myVariable = frm.withdraw.value / 5;
    	
    	if (myVariable != 0) {
    		showError("Invalid amount")
    		frm.withdraw.focus()
    		frm.withdraw.select()
    		return false
    	}
    Code (markup):
    Where is problem??!
     
    ebusinesscenter, Jan 1, 2008 IP
  2. temp2

    temp2 Well-Known Member

    Messages:
    1,231
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    150
    Digital Goods:
    2
    #2
    I think you should use
     
    temp2, Jan 2, 2008 IP
  3. hogan_h

    hogan_h Peon

    Messages:
    199
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    0
    #3
    It can't work like that, you will get true for every number greater 4.
    For Example: myVar = 55 / 5;
    Result is 11, and 11 is != 0

    Try this:
    
    var myVariable = parseInt(frm.withdraw.value) % 5;
    	
    if (myVariable != 0) {
    	showError("Invalid amount")
    	frm.withdraw.focus()
    	frm.withdraw.select()
    	return false
    }
    
    Code (markup):
     
    hogan_h, Jan 2, 2008 IP