|
-
Oct 14th, 2000, 04:56 PM
#1
Thread Starter
Fanatic Member
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
-
Oct 14th, 2000, 05:11 PM
#2
Hyperactive Member
"People who think they know everything are a great annoyance to those of us who do."
-
Oct 14th, 2000, 05:43 PM
#3
Thread Starter
Fanatic Member
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.
-
Oct 14th, 2000, 07:31 PM
#4
Frenzied Member
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
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Oct 14th, 2000, 09:23 PM
#5
Thread Starter
Fanatic Member
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
-
Oct 14th, 2000, 11:09 PM
#6
Frenzied Member
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
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Oct 14th, 2000, 11:26 PM
#7
Thread Starter
Fanatic Member
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.
-
Oct 15th, 2000, 02:45 AM
#8
Frenzied Member
Actually, if the error is on page2.asp, post the code from it...
oOOo--oOOo
__ /\/\onte96
oOOo--oOOo
Senior Programmer/Analyst
MCP
[email protected]
[email protected]
Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..
-
Oct 15th, 2000, 03:18 AM
#9
Thread Starter
Fanatic Member
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.
-
Oct 16th, 2000, 02:23 AM
#10
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.
-
Oct 16th, 2000, 03:29 AM
#11
Frenzied Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|