Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student) (http://www.velocityreviews.com/forums/t874413-req-could-someone-assist-in-correcting-this-code-new-javascript-student.html)

Sue 12-09-2003 03:13 AM

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

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>

Lee 12-09-2003 03:26 AM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
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.


Michael Winter 12-09-2003 09:55 AM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
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.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk")

Sue 12-09-2003 03:15 PM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
On 8 Dec 2003 19:26:39 -0800, Lee <REM0VElbspamtrap@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


Brian 12-09-2003 03:24 PM

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

"Sue" <SueWo@comcast.net > wrote in message
news:6na89v4ubk9jgrbg2n370ff291lsoc4krf@4ax.com...
> On 8 Dec 2003 19:26:39 -0800, Lee <REM0VElbspamtrap@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



Lee 12-09-2003 05:05 PM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
Brian said:
>
>
>"Sue" <SueWo@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>


Sue 12-10-2003 01:29 AM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
On 9 Dec 2003 09:05:31 -0800, Lee <REM0VElbspamtrap@cox.net> wrote:

>Brian said:
>>
>>
>>"Sue" <SueWo@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




Richard Cornford 12-10-2003 07:58 AM

Re: REQ: Could Someone assist in correcting this code ::::::::>>>(New JavaScript Student)
 
"Sue" <SueWo@comcast.net > wrote in message
news:8ctctvcujqfvqe03e89k1j3are5hq7sn62@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.




All times are GMT. The time now is 11:02 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.