473,379 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

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.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

Aug 16 '06 #1
1 1406

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.

Aug 16 '06 #2

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

Similar topics

3
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...
136
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...
27
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...
13
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</...
14
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</...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.