Code Snippet - Help

Results 1 to 2 of 2

Thread: Code Snippet - Help

  1. #1
    Join Date
    Dec 1969

    Default Code Snippet - Help

    function form1_onsubmit(script, latest) {<BR> var vers = trimRegEx(form1.viewVrsn.value);<BR> if(vers == "")<BR> {<BR> alert("Please Enter a Version to View");<BR> form1.viewVrsn.value = "";<BR> form1.viewVrsn.focus();<BR> return(false);<BR> }<BR> if(vers &#062; latest)<BR> {<BR> var msg = "Version " + vers + " has not been created!";<BR> alert(msg);<BR> form1.viewVrsn.value = "";<BR> form1.viewVrsn.focus();<BR> return(false);<BR> }<BR> var url = "script.asp?version=" + vers + "&script=" + script;<BR> var title = script + "Display";<BR> var OpenWindow =, script);<BR> return(false);<BR>}<BR><BR>When I enter in a 9 in the form and latest = 74, why does the second &#039if statement&#039 execute? I put a 4 in there and it works fine. Is it only testing the first number?

  2. #2
    Join Date
    Dec 1969

    Default formfield.value is always a string...

    It is doing a STRING comparison! Just as "i" is greater than "gd", so is "9" greater than "74".<BR><BR>(The .value of any form field is always a string until/unless you convert it.)<BR><BR>Convert both values to numbers and *then* do the comparison. Such as:<BR><BR>vers = parseInt(vers)<BR>latest = parseInt(latest) &#039 this one may not be needed!<BR>if ( vers &#062; latest ) ...<BR><BR><BR><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