Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP to write Javascript

    I have two database tables that are linked on a 12 digit alphanumeric field (I know that's bad, but I didn't design it and it has to be this way b/c that's how we get the data). Normally, I would just put a drop down for users to select which code that one to associate it, but in this case the lookup table consists of 12,000+ rows. What I am trying to do on the form is to expand my form validation as much as I can so that if the rules for code don't match then the form doesn't get submitted. Let me break down the value of the field:

    digits 1 & 2 are numeric.
    digit 3 is either 0 or N
    digit 4 is a value from another lookup table
    digit 5 & 6 are 0s (for now)

    The problem I am having is that I want my regular expression to include knowledge of the fourth digit. Currently the values can be C, E, S or T and the administrators of the site have the ability to change those values. So ideally, I want to hit the database to see what values are valid for that field. I know that I could use asp to write out all of the JavaScript to the form and then for that part of the regular expression I could hit the database, but I was hoping for a simpler solution since this is the only part of the form that needs database validation before submitting the form.

    This is what I have currently for my validation:
    Code:
    		<script language="javascript">
    		<!--
    			function validate(theform){
    			
    				var reCoverageCd1 = /^\d{2}[0N]{1}\w{1}[0]{2}/;
    				if (theform.coverage_cd1.value == ""){
    					alert("You forgot to fill in the Coverage Code Box1");
    					return (false);
    				}
    				else if (!reCoverageCd1.test(theform.coverage_cd1.value)) {
    					alert("You have entered an invalid coverage code in box 1.");
    					return (false);
    				}
    			}
    		//-->
    		</script>

  • #2
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    What about something like this?
    Code:
    <%
    'get the unique alphavalues
    Set oRS = oConn.Execute "SELECT DISTINCT fieldName FROM tableName WHERE thisField = 'someCondition';"
    If Not oRS.EOF Then
        Dim x : x = "" 
        Do Until oRS.EOF
            x = x & oRS("fieldName") & "|"
            oRS.MoveNext
        Loop
    End If
    oRS.Close
    Set oRS = Nothing
    dim z : z = Len(x)
    x = Left(x, z-1) 'remove the trailing |
    %>
                             <script language="javascript">
    		<!--
    			function validate(theform){
    			
    				var reCoverageCd1 = /^\d{2}[0N]{1}\[<%=x%>]{1}[0]{2}/;
    				if (theform.coverage_cd1.value == ""){
    					alert("You forgot to fill in the Coverage Code Box1");
    					return (false);
    				}
    				else if (!reCoverageCd1.test(theform.coverage_cd1.value)) {
    					alert("You have entered an invalid coverage code in box 1.");
    					return (false);
    				}
    			}
    		//-->
    		</script>

  • #3
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Because you can't mix ASP inside of a Javascript tag.

  • #4
    Regular Coder
    Join Date
    May 2005
    Location
    Michigan, USA
    Posts
    566
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes you can. I do it all over the place.
    Note: I do not test code. I just write it off the top of my head. There might be bugs in it! But if any thing I gave you the overall theory of what you need to accomplish. Also there are plenty of other ways to accomplish this same thing. I just gave one example of it. Other ways might be faster and more efficient.

  • #5
    Regular Coder
    Join Date
    Sep 2004
    Posts
    152
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, I always thought you couldn't do that. So I'll give it try and let you know how it works.

  • #6
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Yeah you can because by the time the Javascript runs the ASP code has already been executed and done away with.
    OracleGuy

  • #7
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,065
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Quote Originally Posted by neocool00
    Because you can't mix ASP inside of a Javascript tag.
    I mix server side code(asp and php) inside of client side Javascript all the time.


  •  

    Posting Permissions

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