Results 1 to 11 of 11

Thread: client side form validation w/javascript on a ASP page

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    howdy,
    I want to verify that a user has entered numbers into a form using javascript before the page is sent back to the server.
    any suggestion on how to do this?
    I can do the asp page and the form validation page(one asp,one html w/javascript) but I can't combine the two.

    I will post my code if you need.
    thank you
    pnj

  2. #2
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    292
    Does this link cover what you need?:
    http://www.builder.com/Programming/Javascript/ss09.html
    "People who think they know everything are a great annoyance to those of us who do."

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    not really....

    here is my code.my problem lies in incorporating javascript in an ASP page.
    +++++++++++++++++++++++++++++++++
    <%
    Response.Write "<h3>$100,000 Club</h3>"
    Response.Write "<form name=theclub action=page2.asp method=post>"
    Response.Write "<input type=text name=""start""> Starting Salary<br>"
    Response.Write "<input type=text name=""raise"">Yearly % of income raise<br>"
    Response.Write "<input type=text name=""year"">Starting Year<br>"
    Response.Write "<input type=submit value=""submit"" onClick=java()><input type=reset value=clear>"


    Response.Write "<script language=javascript>"
    Response.Write "<!--"
    Response.Write "function java()"
    Response.Write "{"
    Response.Write "if document.theclub.start.value !="" "";"
    Response.Write "location.href=page2.asp"
    Response.Write "return true;"
    Response.Write "else{"
    Response.Write "alert(enter something)return false;"
    Response.Write "}"
    Response.Write "}//-->"
    Response.Write "</script>"

    %>

    +++++++++++++++++++++++++++++++++++++++++


    when the user fills in the form and clicks the submit button
    I want to call the javascript function and verifie that they actually filled the form out.

    right now I get this error :
    Microsoft VBScript runtime error '800a000d'

    Type mismatch: '[string: ""]'

    /asp/page2.asp, line 16

    thanks.
    pnj

  4. #4
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    For starters, you want to submit your form. Just calling the 2nd page will not pass any of your form data to it. Instead of the location.href you should do theclub.submit()

    Not sure what the javascript equivilent to IsNumeric() is though...


    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    monte96_@hotmail.com
    monte96@vbgarage.com


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    huh?

    I'm not sure what you meen exactly.

    I can get this to work (with slightly different syntax) if I don't use any javascripting. the form works and does what I want it to. but I don't know how to incorporate the javascript function w/ it.

    thanks
    pnj

  6. #6
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Actually, as I look at your code again, the script is executed on the click of the submit button so you don't need to put the location.href in there at all, return true will submit it and redirect to page2.asp
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    monte96_@hotmail.com
    monte96@vbgarage.com


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537

    nope

    I took out the part you said.
    if the form is filled out completly then it works.(calls the correct page and sends the correct variable)
    if I don't fill out the form the javascript should take over and give an alert.
    but instead I get an error on the next page(the second page is still called up from the server)
    ________________________________
    Type mismatch: '[string: ""]'

    /asp/page2.asp, line 18
    ________________________________

    what is strange is that,like i said, if the form is filled out it works.

    would you like me to post the code again for you?

    I am really lost w/ this stuff.

    thanks again.
    pnj

  8. #8
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    Actually, if the error is on page2.asp, post the code from it...

    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    monte96_@hotmail.com
    monte96@vbgarage.com


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    here is the code for both pages.
    page 1:
    +++++++++++++++++++++++++++++++++++++++++++
    <%
    Response.Write "<h3>$100,000 Club</h3>"
    Response.Write "<form name=theclub action=page2.asp method=post>"
    Response.Write "<input type=text name=""start""> Starting Salary<br>"
    Response.Write "<input type=text name=""raise"">Yearly % of income raise<br>"
    Response.Write "<input type=text name=""year"">Starting Year<br>"
    Response.Write "<input type=submit value=""submit"" onClick=java()><input type=reset value=clear>"


    Response.Write "<script language=javascript>"
    Response.Write "<!--"
    Response.Write "function java()"
    Response.Write "{"
    Response.Write "if (document.theclub.start.value !="" "");"
    'Response.Write "location.href=page2.asp"
    Response.Write "return true;"
    Response.Write "else{"
    Response.Write "alert(fill out the form)return false;"
    Response.Write "}"
    Response.Write "}//-->"
    Response.Write "</script>"

    %>

    +++++++++++++++++++++
    and page 2
    +++++++++++++++++++++
    <%
    option explicit

    dim start, raise, year

    start= Request.Form ("start")'starting salary
    raise = Request.Form ("raise")'raise amount per year
    year = Request.Form ("year")'starting year


    Response.Write "<table border=1 width=300><tr><td>Salary</td><td>Year</td></tr>"


    do while start <= 100000
    dim newYear
    year = year + 1
    start = start + ((raise/100)* start)
    Response.Write "<tr><td>" & FormatCurrency(start,2) & " </td><td>" & year &"</td></tr>"
    newYear=newYear + 1
    loop

    Response.Write "<tr><td colspan=""2"">" & newYear & " years until" & FormatCurrency(start,2) & "</td></tr>"
    Response.Write "</table>"

    Response.Write "<center>"& newYear & "</center>"
    Response.Write start & " " & raise & " " & year
    Response.Write"<br>"

    %>
    ++++++++++++++++++++++++++++++++++++++++++++++++

    thanks.
    pnj

  10. #10
    Guest
    Why not try something like this:


    Response.Write "<script language=javascript>"
    Response.Write "<!--"
    Response.Write "function java()"
    Response.Write "{"
    Response.Write "if (document.theclub.start.value =="" "")"
    Response.Write "{"
    Response.Write "alert(""Fill in start please!"");"
    Response.Write "document.theclub.start.focus()"
    Response.Write "return false"
    Response.Write "}"
    Response.Write "if (document.theclub.raise.value =="" "")"
    Response.Write "{"
    Response.Write "alert(""Fill in raise please!"");"
    Response.Write "document.theclub.raise.focus()"
    Response.Write "return false"
    Response.Write "}"
    Response.Write "if (document.theclub.year.value =="" "")"
    Response.Write "{"
    Response.Write "alert(""Fill in year please!"");"
    Response.Write "document.theclub.year.focus()"
    Response.Write "return false"
    Response.Write "}"
    Response.Write "return true;"
    Response.Write "}//-->"
    Response.Write "</script>"


    Of course this doesn't test if the value is numeric yet, since I don't really have a clue to that code in javascript either. I might get back to you on that.

  11. #11
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    here's a function to check that the contents are numeric

    Code:
    function check(contents) {
        if (((contents / contents) != 1) && (contents != 0)) {alert('Please enter only a number into this text box')}
    }

    I it seems unnecessarily complicated writing your javascipt using response.write()

    if server side variables have to be written within the javascript you have no choice, but this is just plain client-side stuff.
    Mark
    -------------------

Posting Permissions

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



Click Here to Expand Forum to Full Width