Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation Preventing ASP Submit?

Status
Not open for further replies.

hedidit

Technical User
Joined
Jul 21, 2005
Messages
142
Location
GB
Hi,

I've got a page using ASP to save user input to a database. Anyway the page worked fine, but now if a user tries to copy and paste text from MS Word into my field and submit nothing happends... the page doesn't even try to submit.

The form goes to the validate javasscript onSubmit so I'm wondering whether the cobmination of copied text from word and my validate script is preventing the page from submitting... can someone have a look at my javascript validation script? It's originally from these boards i think... sorry can't remember who

Code:
<style>.errorcolor {background: ffaaaa}</style>
<style>.goodcolor {background: ffffff}</style>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

tempobj.className='goodcolor';


if (tempobj.name.substring(0,3)=="req") {

if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(3,30).toUpperCase();
alert("Please make sure the "+shortFieldName+" field was properly completed (Highlighted in red).");

tempobj.className='errorcolor';


return false;
}
else

return true;
}
//  End -->
</script>

Cheers
 
Do you get javascript errors (on the status bar in IE)?

Show your form code as well. How is the function called, does it happen every time data is pasted from any word document or just certain data from a certain document?
You might be getting embeded characters that do not display on the web page but cause validation errors.


It's hard to think outside the box when I'm trapped in a cubicle.
 
And don't post the same question in 2 forums. If this is an ASP problem, then stick with the ASP forum. If you present your problem as something related to Javascript, don't rewrite what's wrong to make it look like as ASP problem so you can post the same question there.

Lee
 
don't post in 2 forums, good point.

Usually i wouldn't but after speaking to DNG in the ASP forum i had another look and figured it was probably a javascript rather than an ASP problem as the form wasn't getting so far as submitting, thats why i then posted in here...

Anyway yep error message refers to line 152 saying object required.

Code:
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function checkrequired(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];

tempobj.className='goodcolor';


if (tempobj.name.substring(0,3)=="req") {

if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(3,30).toUpperCase();
[b][line 152][/b]alert("Please make sure the "+shortFieldName+" field was properly completed (Highlighted in red).");

tempobj.className='errorcolor';


return false;
}
else

return true;
}
//  End -->
</script>

It only happens when a user tries to copy and paste text from a word document that is or has been bullet pointed...
even text thats had bullet points removed causes the error so I guess word still leaves some odd characters?

Cheers for the help
 
MS Word "smart" quotes and apostrophes aren't standard quotes and apostrophes, either, and can cause problems if you use string manipulation methods. Javascript doesn't always handle things well in strings with characters less than ANSI 32 (the space bar) or greater than "z".

Lee
 
Yep, Word must be leaving something in that causes your validation code to choke.
The thing is, usually if the javascript errors out the function quits and the form WILL get submitted even though it would have failed validation because the submit action had already been started without a return false to cancel it.

Again though, you did not post your form, only your javascript function so I cannot tell how the function call occurs or how the form submits.

And if you post the HTML code make sure it is the code that it is the result of the page in the browser rather than the raw code with the intermingled ASP since we cannot tell how the ASP code evaluates here.
In other words run the page then do a view source on the page and that is the code to post since that is the result after any ASP code has been processed. Makes it easier for us to troubleshoot any specific Javascript related issues.

You may want to filter any field text prior to testing using a regular expression to pull out any characters that do not belong but how that works depends on what characters will be valid for that field.



It's hard to think outside the box when I'm trapped in a cubicle.
 
Sorrt form code is:

Code:
<form name="form1" onSubmit="return checkrequired(this)">
'----lots of HTML and a few text areas etc
<textarea name="furmeas" rows="5" cols="84"><%=(lg.Fields.Item("furmeas").Value)%></textarea>
</Form>

I tried typing in the text instead of copying and pasting from word and it works fine until there is a certain amount of text in the above textarea... why would me having around three lines of text in a textarea prevent my form from submitting / upset my javascript validation? The text i typed in has no 'odd' characters in it etc...

actually the text in it isn't passed to my validate script



 
If you submit with a get there's a limit to the number of bytes you can transfer from the form. I'd suggest making your form's method post. You didn't show any method specified in your example, and the default is get.

Lee
 
really? i didn't realise that was the default? I'll check it out... will be pleased but slightly annoyed to have been delayed by something so minor!

Thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top