473,405 Members | 2,185 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,405 software developers and data experts.

REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)

Sue

Hello! I am back with another question.

Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.

At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.

************************************************** ************************

<html>

<head>
<title>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate(DataEntry) {
// validate the Firstname
var FstName=document.Register.FirstName.value
if (FstName == " ") {
alert("Please enter your Firstname")
document.Register.FirstName.value=" "
document.Register.FirstName.focus()
}
else {

// validate the Lastname
var LstName=document.Register.LastName.value
if (LstName == " ") {
alert("Please enter your Lastname")
document.Register.LastName.value=" "
document.Register.LastName.focus()
}
else {

// validate Age as be numeric
var YearsOld=document.Register.Age.value
var YearsOld=parseInt(YearsOld,10)
if (isNaN(YearsOld)) {
alert("Age is not numeric")
document.Register.Age.value=" "
document.Register.Age.focus();
}
else {

// validate the @ sign and the period as being the fourth
from the last character in an e-mail address
var RegeMail=document.Register.eMail.value
var atSign = RegeMail.indexOf("@")

var Period=document.Register.eMail.value
var PPeriod = Period.indexOf('.');
var LPeriod = Period.length - 4

if (RegeMail == " " || atSign == -1 || LPeriod !=
PPeriod) {
alert("Please enter a valid e-mail address")
document.Register.eMail.value = " "
document.Register.eMail.focus()
}
else {

// validate the Gender in a drop down menu
var sex=document.forms[0].Gender.selectedIndex;
if (sex==0) {
alert("You must select your GENDER from the drop-down
Menu.");
document.forms[0].Gender.focus();
}
else
{

Gender_selection=document.forms[0].Gender.options[sex].value;
return true;
}
}
}
}
}
}
//-->
</script>
</head>

<body>
<FORM Name="Register">
<table border="0" width="90%">

<!-- Begining of the first line of the form for entering data. -->
<tr>
<td>Enter Your Firstname :</td><td align="center">
<Input Type="text" Name="FirstName" value=" "></td>
<td>&nbspEnter Your Age :</td> <td align="center">
<Input Type="numeric" Name="Age" value=" "></td>
<td align="center">Select your : <SELECT NAME="Gender" SIZE=1 >
<OPTION SELECTED VALUE=""> --- Select Gender ---
<OPTION VALUE="Male">Male
<OPTION VALUE="Female">Female
</SELECT>
</td>
</tr>
<!-- ending of the first line of the form for entering data. -->

<!-- Begining of the second line of the form for entering data. -->
<tr>
<td align="center">Enter Your Lastname :</td><td align="center">
<Input Type="text" Name="LastName" value=" "></td>
<td align="center">Enter Your Email Address :</td> <td
align="center">
<Input Type="text" Name="eMail" value=" "></td>
<td align="right"><Input Type="button" Value="Send"
onClick="Validate(Register)">
<Input
Type="Reset">&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</td>
</tr>
<!-- ending of the second line of the form for entering data. -->

</table>
</form>
</body>
</html>
Jul 20 '05 #1
8 1931
Lee
Sue said:


Hello! I am back with another question.

Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.

At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem. <Input Type="button" Value="Send" onClick="Validate(Register)">


It's not clear why you expect the fields to be cleared.
Your "Send" button doesn't actually send any data.
It just executes your Validate() function.

If you want it to send the data, you should use an input of
type "submit", instead of "button", and instead of using the
onclick event handler of the button, you should execute your
Validate() function within the onsubmit event handler of the
form.

Jul 20 '05 #2
Lee wrote on 09 Dec 2003 at Tue, 09 Dec 2003 03:26:39 GMT:
Sue said:

<Input Type="button" Value="Send"
onClick="Validate(Register)">


If you want it to send the data, you should use an input of
type "submit", instead of "button", and instead of using the
onclick event handler of the button, you should execute your
Validate() function within the onsubmit event handler of the
form.


You'll also want to make sure that you use the return keyword so that
the result of the validation allows or cancels the submission.

Mike

--
Michael Winter
M.******@blueyonder.co.invalid (replace ".invalid" with ".uk")
Jul 20 '05 #3
Sue
On 8 Dec 2003 19:26:39 -0800, Lee <RE**************@cox.net> wrote:
Sue said:


Hello! I am back with another question.

Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.

At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.

<Input Type="button" Value="Send" onClick="Validate(Register)">


It's not clear why you expect the fields to be cleared.
Your "Send" button doesn't actually send any data.
It just executes your Validate() function.

If you want it to send the data, you should use an input of
type "submit", instead of "button", and instead of using the
onclick event handler of the button, you should execute your
Validate() function within the onsubmit event handler of the
form.

Lee,

I am having to take this JavaScript class over the Internet and other
than the textbox, I have no help. Therefore, I am not sure about what
you are talking about but I tried SUBMIT and it does clear the fields.
However, if invalid data is entered and I press Send, all fields are
cleared and the info has to be reentered.

If you could make the changes to the code that you mentioned and
post it I would greatly appreciate it.

Thanks.

Sue

Jul 20 '05 #4

"Sue" <Su***@comcast.net > wrote in message
news:6n********************************@4ax.com...
On 8 Dec 2003 19:26:39 -0800, Lee <RE**************@cox.net> wrote:
Sue said:


Hello! I am back with another question.

Remember I am a new JavaScript student and I am aware that this code
does not check for all the possibilities and that as a "NEW"
JavaScript student I am not expected to check for everything.

At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.

<Input Type="button" Value="Send" onClick="Validate(Register)">


It's not clear why you expect the fields to be cleared.
Your "Send" button doesn't actually send any data.
It just executes your Validate() function.

If you want it to send the data, you should use an input of
type "submit", instead of "button", and instead of using the
onclick event handler of the button, you should execute your
Validate() function within the onsubmit event handler of the
form.

Lee,

I am having to take this JavaScript class over the Internet and other
than the textbox, I have no help. Therefore, I am not sure about what
you are talking about but I tried SUBMIT and it does clear the fields.
However, if invalid data is entered and I press Send, all fields are
cleared and the info has to be reentered.

If you could make the changes to the code that you mentioned and
post it I would greatly appreciate it.

Thanks.

Sue


Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
the learning process is using resources to find solutions by your self....

B
Jul 20 '05 #5
Lee
Brian said:


"Sue" <Su***@comcast.net > wrote:
If you could make the changes to the code that you mentioned and
post it I would greatly appreciate it.

Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
the learning process is using resources to find solutions by your self....


It's certainly more ethical than the students who try to pretend
that it isn't homework: "My client would like a form that allows
the visitor to type his name and have the message 'Hello, <name>!'
appear in a popup alert box."

I don't mind answering questions or giving tips, but I won't go
so far as to complete the assignment.

Here's a simple example of form validation. In production,
I would use a regular expression to test to see if the field
contains valid data, but that's beyond the scope of this
assignment.

<html>
<head>
<script type="text/javascript">
function Validate(f){
// f is a reference to the form to be validated.
// This function returns true if all fields are valid
// or false if any are invalid.

if(f.FirstName.value==""){ // Note: no space between quotes
alert("Please enter a value for First Name");
f.FirstName.focus();
return false;
}
if(f.LastName.value==""){
alert("Please enter a value for Last Name");
f.LastName.focus();
return false;
}

return true; // All fields are valid.

}
</script>
</head>
<body>
<form onsubmit="return Validate(this)">
First Name: <input name="FirstName"><br>
Last Name: <input name="LastName"><br>
<input type="Submit" value="Send">
</form>
</body>

Jul 20 '05 #6
Sue
On 9 Dec 2003 09:05:31 -0800, Lee <RE**************@cox.net> wrote:
Brian said:


"Sue" <Su***@comcast.net > wrote:

If you could make the changes to the code that you mentioned and
post it I would greatly appreciate it.

Hmmmm... Asking a newsgroup to fix your homework? Is that ethical? Part of
the learning process is using resources to find solutions by your self....


It's certainly more ethical than the students who try to pretend
that it isn't homework: "My client would like a form that allows
the visitor to type his name and have the message 'Hello, <name>!'
appear in a popup alert box."

I don't mind answering questions or giving tips, but I won't go
so far as to complete the assignment.

Here's a simple example of form validation. In production,
I would use a regular expression to test to see if the field
contains valid data, but that's beyond the scope of this
assignment.


Look guys I am not wanting to get into a ethical debate, but in most
all of the computer related classes I have taken "in the classroom"
the instructor has said, "I do not have time to provide all the help
everyone needs so if you can help your neighbor please do so."

Since I am not in class with classmates and the instructor stays
confused as to who sent what email I thought I would ask for help
here. I feel that if I were asking someone to do the complete
assignment that would be unethical. As you can see I am not asking
that. I am only asking for help on a small part and the code that I
posted is probably only one-fourth of my overall project.

Thanks for you help Lee. I will see if I can fix my problem.

Sue

Jul 20 '05 #7
"Sue" <Su***@comcast.net > wrote in message
news:8c********************************@4ax.com...
<snip>
... and the instructor stays
confused as to who sent what email ...


Given everything you have previously mentioned (such as the requirement
to write e-mail address validators that have zero relation to how the
task must be approached in the real world) it might be time to name the
outfit providing this online "training". So they can be associated with
the consequences of the quality of service they provide (particularly in
google searches).

Richard.
Jul 20 '05 #8
In article <tr********************************@4ax.com>, Sue
<Su***@comcast.net> wrote:
At any rate, the problem I am having with the following code is that
it does not clear the fields once I press the SEND button. So can
anyone here enlighten me as to what is causing the problem.

************************************************** ************************

<html>

<head>
<title>JavaScript Project</title>
<SCRIPT LANGUAGE="JAVASCRIPT">
<!--Hide from old browsers
function Validate(DataEntry) {
// validate the Firstname
var FstName=document.Register.FirstName.value
if (FstName == " ") {
alert("Please enter your Firstname")
document.Register.FirstName.value=" "
document.Register.FirstName.focus()
}
else {

<SNIP>

You only clear the field if the field is blank. Move the end if bracket
up 2 lines.

--
Dennis M. Marks
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #9

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

Similar topics

3
by: TXSherry | last post by:
Hi, I cannot seem to wrap my brain around preg_replace. Though I've read the help file backwords and forwards. :/ Hoping someone can give me a solution here. Problem: Given string 'str'...
9
by: Henrik | last post by:
In Java you can write something like this. Does anyone know how to do this in javascript? "byte b=Integer.parseInt(int value or String).byteValue;"
4
by: Andy Leszczynski | last post by:
watch this: http://www.turbogears.org.nyud.net:8090/docs/wiki20/20MinuteWiki.mov or read this: http://www.turbogears.org.nyud.net:8090/docs/wiki2 0/page4.html should not it be: 2 def...
2
by: julie.siebel | last post by:
I KNOW this can't be as hard as I am making it. I have a travel client with two related websites. On the homepage of the new site (Call it "Site A") I am building for them, there is a link to a...
14
by: Schraalhans Keukenmeester | last post by:
I am building a default sheet for my linux-related pages. Since many linux users still rely on/prefer viewing textmode and unstyled content I try to stick to the correct html tags to pertain good...
1
by: Steve Sobol | last post by:
http://gallery.stevesobol.com/activex-plain.html works in Firefox 1.5 and Opera 9 but not in IE 6, and I can't figure out why. The IE developer toolbar's DOM inspector shows the OBJECT tag and...
1
by: Bob | last post by:
Hi, Hope you can help me with this one. I'm at my wits end. I'm trying to create an intelligent edit-box like the excellent "Customer" one at the URL: ...
3
by: Yash | last post by:
Hi all, I found that while we are updating our application, the application is not known to tomcat, untill it is completed. So tomcat sends 503 page as resource not found. I want to know is...
2
by: vincentregent | last post by:
Hi, When I try to create a new website, the web.config file in the solution explorer is missing. Normally, asp.net should create it by default. Can someone help me??? thanx
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: 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
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.