473,698 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript Form Validation Issue

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.p l". 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='javas cript'>

function checkContent (strng) {
var error = "";
if (strng == ""){
error = "Please enter some content for this FAQ.\n";
}
return error;
}
function validate()
{
var why = "";
why += checkContent(ad dFAQ.content.va lue);
if (why != ""){
alert(why);
return false;
}
else{
document.addFAQ .submit();
return true;
}
}
</SCRIPT>
</HEAD>
<BODY>
<form name='addFAQ' id='addFAQ' action='addFAQA ction.pl' method='post'>
<table>
<tr>
<td>FAQ Content:<br></td>
HTML
<td><textarea id='content' name='content' cols='70'
rows='20'>$cont ent</textarea></td>
print <<"HTML";
</tr>
<tr>
<td></td>
<td>
<input type="submit" name="update" value="Update Page"
onClick=\"docum ent.addFAQ.acti on='addFAQ.pl'\ ">
<input type="submit" name="Submit" value="Submit FAQ"
onSubmit='javas cript:validate( );'>
</td>
</tr>
</table>
</form>
</BODY>
</HTML>
HTML

Aug 16 '06 #1
1 1419

Nigel wrote:
<SCRIPT language='javas cript'>
The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">
<form name='addFAQ' id='addFAQ' action='addFAQA ction.pl' method='post'>
[snip]
<input type="submit" name="update" value="Update Page"
onClick=\"docum ent.addFAQ.acti on='addFAQ.pl'\ ">
<input type="submit" name="Submit" value="Submit FAQ"
onSubmit='javas cript: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.

Aug 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2299
by: fig000 | last post by:
Hi, I'm relatively new to Javascript so please bear with me on what might sound like silly questions. This is what I want to do: I'm working in classic asp (I have to for this project). I need to: 1. Click a submit button on an asp page, calling another page that saves the contents of that form to a database and then displays
136
9379
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
27
4745
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
13
323
by: Mtek | last post by:
Hi, We have a form defined with buttons like this: <a class="save_menu" href="javascript:document.Detail_Screen.action = 'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</ a> The form also has an onSubmit action to vall a validation routine:
14
2182
by: Mtek | last post by:
Hi, We have a form defined with buttons like this: <a class="save_menu" href="javascript:document.Detail_Screen.action = 'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</ a> The form also has an onSubmit action to vall a validation routine:
0
8672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.