By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,472 Members | 1,219 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,472 IT Pros & Developers. It's quick & easy.

Trouble with client side validation

P: 4
Hi all,
I have a program that has multiple passes between the server side script and the client side. I am using vbscript. The newest version that I have written does not work.The first time the server side code runs, it sends a single text input and an input type="submit". When I click on the submit button, the _onsubmit function is not triggered. I printed out the code sent to the browser by both the new ASP and the old. They look identical, but the old one works. Is there something that I could be doing on the server side that is disabling the _onsubmit function? The first statement in the function is a msgbox so I know it is not getting called.

Thanks for any assistance.
Jim
Oct 18 '06 #1
Share this Question
Share on Google+
8 Replies


P: 50
Do you have any javascript in there?
Perhaps an onsubmit= statement....
If not, could we see the form tag and maybe the submit button code?
Oct 18 '06 #2

P: 4
Do you have any javascript in there?
Perhaps an onsubmit= statement....
If not, could we see the form tag and maybe the submit button code?
Sure. I hope that this isn't inappropriately large to post.

Jim

<SCRIPT LANGUAGE="vbscript">
<!--
sub window_onload
' set onload characteristics for each form
for each form in window.document.forms
if form.name = "form1" then ' select work order form
if FormMode = "GetSN" then
form1.SerNum.value=""
form1.SerNum.focus
end if
end if
next
end sub

function form1_onsubmit ' validation for form1
msgbox "Nuts! "' & Form1.mode.value
form1_onsubmit = false ' cancel onsubmit event if CR pressed
if Form1.mode.value = "Sernum" then
form1.mode.value = ""
if len(form1.SerNum.value) = 0 then
msgbox "Please enter a serial #."
form1.SerNum.value = ""
form1.SerNum.focus
DataValid = false
exit function
else
ucase(form1.SerNum.value)
end if
end function
-->
</SCRIPT>

<HTML>
<head>
<META name=VI60_defaultClientScript content=VBScript>
<!-- Reference style sheet -->
<link rel=stylesheet href="/styles/rwmmoistyle.css" TYPE="text/css">
</head>
<BODY>
<table width=100% bordercolordark=White bordercolorlight=White>
<CENTER>FormMode =GetSN xxx </CENTER>
<Center>
<BR>
<TR>
<TD align=left><H3>Instrument Activity Logging</H3></TD>
<TD align=right><h3>Operator - Jim(39)</h3></TD>
</TR>
</Center>
</table>
<hr>
<FORM action="InstrumentActivity_V0.8.asp" method="post" name=form1>
<center>
<table cols=2 cellspacing=5>
<CENTER><TR><H2>
<TD align = center>Enter Instrument Serial Number :</TD>
<TD align = left><INPUT type="text" name="SerNum" size="7"></TD>
</TR></H2></CENTER>
</Table>
<BR><BR>
<HR>
<table cols=2 cellspacing=5>
<TR>
<TD>
<INPUT type="hidden" value="Sernum" name=mode>
<INPUT type="submit" value=" SUBMIT " name=btnSubmit>
</TD>
<TD>
<Input type="button" value="Return to Homepage" name=GoHome onclick= 'window.navigate "datamain.asp"' language=vbs>
</TD>
</TR>
</center>
</Form>

</BODY>
</HTML>
Oct 18 '06 #3

P: 1
Hi guys. could someone please tell me how to check if 2 different textbox entries ave the same entry and if they are not, output an error message on the client side
Oct 18 '06 #4

P: 50
Maybe im not seeing something, but should you not have:

Expand|Select|Wrap|Line Numbers
  1. <FORM action="InstrumentActivity_V0.8.asp" method="post" name=form1 OnSubmit="YourVBFunction">
I mean how is you function being called????
Oct 20 '06 #5

P: 50
Hi guys. could someone please tell me how to check if 2 different textbox entries ave the same entry and if they are not, output an error message on the client side

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function compare(){
  3. if (document.form.text1.value == document.form.text2.value){
  4. return true;
  5. }
  6. else
  7. {
  8. alert ("values must match");
  9. return false;}
  10.  
  11. </script>
  12.  
  13. ----------------------------------------------------------------------------------
  14.  
  15. <form method="" action="" onSubmit="return compare(this);" name="form1">

Basically.
Oct 20 '06 #6

P: 4
Maybe im not seeing something, but should you not have:

Expand|Select|Wrap|Line Numbers
  1. <FORM action="InstrumentActivity_V0.8.asp" method="post" name=form1 OnSubmit="YourVBFunction">
I mean how is you function being called????
By defining the input as Type="submit", when the button is clicked a submit event is triggered. If there is no _onsubmit event handler in the client side code, all of the input data on the form is submitted to the server. This way you can validate the input data on the client before sending it to the server. My problem is that no matter what I put in the client side script, it is not being executed. I have tried _onsubmit and _onclick events, and neither gets executed.
Oct 20 '06 #7

P: 50
I agree the vars are being posted back as request.form values when you click on a submit button.
If you want to process those variables on the server side, then you need to extract them from the post array and run 'em through your sub.

What it seems to me however, is that you wish to validate the fields right there on the client side, before the form actually submits back to the server......

Which leads me back to my original question.... Where is the function being called?!?! If I could make a suggestion, javascript is strictly a client side language and really the appropriate tool for form validations. VBscript imo should be reserved for middleware operations only.

Anyways - either you will need to either explicitly call the function, strip the values from the POST array and run them through the sub, or just rethink the whole thing in javascript terms.

If I am misunderstanding you then i apologize, but i can assure you that the issue is within your program logic.
Oct 20 '06 #8

P: 4
Well, I finally found the problem. If I hadn't cut out as much of the script so as to reduce it's size somebody else might have found it first. I had an elseif statement in the client side script that was missing a then at the end. Can't believe that I didn't get an error message. I inherited a ton of code that was all done in vbscript. I never have done anything in javascript so I really don't know which is better. I'm sure javascript is more widely supported. I'm fairly new to this, but my understanding is that onsubmit is an HTML core attribute event handler. Clicking on an input that is defined in the HTML code as type="submit" will automatically submit the form to the form onsubmit function if present. In this case my form was named form1, so function form1_onsubmit is called. I believe this is also true for javascript.
Oct 23 '06 #9

Post your reply

Sign in to post your reply or Sign up for a free account.