Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Javascript Form Validation Issue

Reply
Thread Tools

Javascript Form Validation Issue

 
 
Nigel
Guest
Posts: n/a
 
      08-16-2006
Hello,

I am creating a Perl CGI page with Javascript which I believe has a
problem with the javascript.

Below is my form which has two submit buttons with two different
actions.
I am having an issue with my "Submit FAQ" button. The "Submit FAQ"
button calls the javascript function validate(). This function is
supposed to check to make sure the 'content' field is populated. If
the field is populated it will go to the action page called
"addFAQAction.pl". If the 'content' field in undefined a message will
be displayed to the user stating to populate the 'content' field.
Currently the functionality does not catch when the 'content' field is
blank and just continues to the action page.

Can anyone see what I might be doing wrong which causes my form not to
catch when 'content' is undefined?

Thanks in Advance.
Nigel


#!/usr/bin/perl -w
use strict;
use CGI;
my $content = param('content');

print <<"HTML";
<HTML>
<HEAD>
<SCRIPT language='javascript'>

function checkContent (strng) {
var error = "";
if (strng == ""){
error = "Please enter some content for this FAQ.\n";
}
return error;
}


function validate()
{
var why = "";
why += checkContent(addFAQ.content.value);
if (why != ""){
alert(why);
return false;
}
else{
document.addFAQ.submit();
return true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<form name='addFAQ' id='addFAQ' action='addFAQAction.pl' method='post'>
<table>
<tr>
<td>FAQ Content:<br></td>
HTML
<td><textarea id='content' name='content' cols='70'
rows='20'>$content</textarea></td>
print <<"HTML";
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="update" value="Update Page"
onClick=\"document.addFAQ.action='addFAQ.pl'\">
<input type="submit" name="Submit" value="Submit FAQ"
onSubmit='javascript:validate();'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
HTML

 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      08-16-2006

Nigel wrote:
> <SCRIPT language='javascript'>


The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">

> <form name='addFAQ' id='addFAQ' action='addFAQAction.pl' method='post'>

[snip]
> <input type="submit" name="update" value="Update Page"
> onClick=\"document.addFAQ.action='addFAQ.pl'\">
> <input type="submit" name="Submit" value="Submit FAQ"
> onSubmit='javascript:validate();'>


1. When you "update the page", you are still submitting the page.
2. The input element does not have an onsubmit event handler, the form
element does.

Personally, I discourage the use of multiple submit buttons, as it
usually seems unnecessary. You could for example, use a checkbox to
indicate you're "updating a page" instead.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
A form validation library with javascript validation Grigory Temchenko Python 0 12-28-2008 08:38 PM
javascript form validation - form action to another asp page iam247@gmail.com ASP General 7 08-20-2005 10:06 PM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven Javascript 3 05-13-2004 12:15 AM
copy and paste form RTF document into field in asp form cause it to bypass field length and javascript validation - how to overcome? NotGiven ASP General 3 05-13-2004 12:15 AM
Form Validation Problem...Persisiting form fields on validation failure. bnp Javascript 4 05-12-2004 12:16 PM



Advertisments