Hello,
I would appreciate any help I can get from anyone who has experience
using javascript. I have an html form containing a number of functions
controlling the submission of data to our database. I now want to
require users to fill in three specific fields before they can submit
the form. I found a function and modified it with my form name
(mainform), and field names(sub 1,2 and 3)
In the head of the document, I added this function to the existing ones
that work successfully:
function required()
{
if (document.mainf orm.sub1.value= =" ")
{
alert("Please Enter Name!");
document.mainfo rm.sub1.focus()
return false;}
return true;
if (document.mainf orm.sub2.value= =" ")
{
alert("Please Enter Position");
document.mainfo rm.sub2.focus()
return false;}
return true;
if (document.mainf orm.sub3.value= =" ")
{
alert("Please Enter Email Address");
document.mainfo rm.sub3.focus()
return false;}
return true;
}
In the body I have
form name ="=mainform"
The other functions that work prevent submission under certain
conditions, but my new function is just ignored. Does anyone have any
suggestions?
Thanks, kdc 7 1248
kdc wrote: Hello, I would appreciate any help I can get from anyone who has experience using javascript. I have an html form containing a number of functions controlling the submission of data to our database. I now want to require users to fill in three specific fields before they can submit the form. I found a function and modified it with my form name (mainform), and field names(sub 1,2 and 3) In the head of the document, I added this function to the existing ones that work successfully:
function required() { if (document.mainf orm.sub1.value= =" ")
That is checking to see if sub1's value is a space. Not what I think you
want.
if (document.mainf orm.sub1.value == '')
{ alert("Please Enter Name!"); document.mainfo rm.sub1.focus() return false;} return true;
Right here, the function is either going to return true or false, any
following code will never be executed.
if (document.mainf orm.sub2.value= =" ") { alert("Please Enter Position"); document.mainfo rm.sub2.focus() return false;} return true;
if (document.mainf orm.sub3.value= =" ") { alert("Please Enter Email Address"); document.mainfo rm.sub3.focus() return false;} return true; }
function required(formRe f){
var alertMessage = '';
if (formRef.sub1.v alue = ''){alertMessag e += "Name Required\n";}
if (formRef.sub2.v alue = ''){alertMessag e += "Position Required\n";}
if (formRef.sub3.v alue = ''){alertMessag e += "Email Required\n";}
if (alertMessage == ''){return true;}
else{alert(aler tMessage);retur n false;}
}
In the body I have
form name ="=mainform"
<form name="mainform" onsubmit="retur n required(this)" >
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Randy Webb wrote: kdc wrote:
Hello, I would appreciate any help I can get from anyone who has experience using javascript. I have an html form containing a number of functions controlling the submission of data to our database. I now want to require users to fill in three specific fields before they can submit the form. I found a function and modified it with my form name (mainform), and field names(sub 1,2 and 3) In the head of the document, I added this function to the existing ones that work successfully:
function required() { if (document.mainf orm.sub1.value= =" ")
That is checking to see if sub1's value is a space. Not what I think you want.
if (document.mainf orm.sub1.value == '')
{ alert("Please Enter Name!"); document.mainfo rm.sub1.focus() return false;} return true;
Right here, the function is either going to return true or false, any following code will never be executed.
if (document.mainf orm.sub2.value= =" ") { alert("Please Enter Position"); document.mainfo rm.sub2.focus() return false;} return true;
if (document.mainf orm.sub3.value= =" ") { alert("Please Enter Email Address"); document.mainfo rm.sub3.focus() return false;} return true; }
function required(formRe f){ var alertMessage = ''; if (formRef.sub1.v alue = ''){alertMessag e += "Name Required\n";}
A good argument for always putting literals on the left when doing
evaluations (unless assignment is actually intended). In this
case, the value of formRef.sub1.va lue is set to '' and the test is
always true (unless the assignment is 'fixed' by older browsers) and
the content of the form element is effectively deleted. Try:
if ( '' = formRef.sub1.va lue ){alertMessage += "Name Required\n";}
will return an error, prompt fixing:
if ( '' == formRef.sub1.va lue ){alertMessage += "Name Required\n";}
if (formRef.sub2.v alue = ''){alertMessag e += "Position Required\n";} if (formRef.sub3.v alue = ''){alertMessag e += "Email Required\n";}
ditto...
--
Rob
RobG wrote: Randy Webb wrote: kdc wrote:
Hello, I would appreciate any help I can get from anyone who has experience using javascript. I have an html form containing a number of functions controlling the submission of data to our database. I now want to require users to fill in three specific fields before they can submit the form. I found a function and modified it with my form name (mainform), and field names(sub 1,2 and 3) In the head of the document, I added this function to the existing ones that work successfully:
function required() { if (document.mainf orm.sub1.value= =" ")
That is checking to see if sub1's value is a space. Not what I think you want.
if (document.mainf orm.sub1.value == '')
{ alert("Please Enter Name!"); document.mainfo rm.sub1.focus() return false;} return true;
Right here, the function is either going to return true or false, any following code will never be executed.
if (document.mainf orm.sub2.value= =" ") { alert("Please Enter Position"); document.mainfo rm.sub2.focus() return false;} return true;
if (document.mainf orm.sub3.value= =" ") { alert("Please Enter Email Address"); document.mainfo rm.sub3.focus() return false;} return true; }
function required(formRe f){ var alertMessage = ''; if (formRef.sub1.v alue = ''){alertMessag e += "Name Required\n";}
A good argument for always putting literals on the left when doing evaluations (unless assignment is actually intended). In this case, the value of formRef.sub1.va lue is set to '' and the test is always true (unless the assignment is 'fixed' by older browsers) and the content of the form element is effectively deleted. Try:
if ( '' = formRef.sub1.va lue ){alertMessage += "Name Required\n";}
will return an error, prompt fixing:
if ( '' == formRef.sub1.va lue ){alertMessage += "Name Required\n";}
if (formRef.sub2.v alue = ''){alertMessag e += "Position Required\n";} if (formRef.sub3.v alue = ''){alertMessag e += "Email Required\n";}
ditto...
-- Rob
Thanks to both of you for your quick feedback.
This is what I added to my program:
function required(mainfo rm){
var alertMessage = '';
if (' '==mainform.sub 1.value ){alertMessage += "Name Required\n";}
if (' '==mainform.sub 2.value){alertM essage += " Position Required\n";}
if (''==mainform.s ub3.value){aler tMessage += "Email Required\n";}
if (alertMessage == ''){return true;}
else{alert(aler tMessage);retur n false;}
}
I wasn't sure whether to use =mainform or ==mainform so I also tried it
with a single =. It continues to ignore it.
I don't want to waste your time so let me ask if the fact that I call
the function by
adding it to another function (checkValues) that is then called in upon
submission matters.
I added required(this) at the end of the list as below:
function checkValues() {
if (! ( checkMonths() && checkTimes() &&
checkRoutes1() &&
checkAges() && checkGenders() &&
checkVars() && checkCauses() && checkPhases() &&
checkPersons() &&
checkFactors() && checkTypes() && checkErrors() &&
required(this) ) ) {
return false;
}
}
I also tried it without the 'this' just in case.
In the body:
<FORM NAME="mainForm" onsubmit="retur n checkValues();"
ACTION="readfil e.php" method="POST">
Thanks again for your help!
kdc wrote: Thanks to both of you for your quick feedback. This is what I added to my program:
function required(mainfo rm){ var alertMessage = ''; if (' '==mainform.sub 1.value ){alertMessage += "Name Required\n";}
You are checking to see if sub1 is a space, not what you wanted.
if (' '==mainform.sub 2.value){alertM essage += " Position Required\n";}
Same there.
if (''==mainform.s ub3.value){aler tMessage += "Email Required\n";} if (alertMessage == ''){return true;} else{alert(aler tMessage);retur n false;}
}
I wasn't sure whether to use =mainform or ==mainform so I also tried it with a single =. It continues to ignore it.
It should be a double ==. My original had the typo in it and got
propogated by me copy/pasting it.
I don't want to waste your time so let me ask if the fact that I call the function by adding it to another function (checkValues) that is then called in upon submission matters.
Yes, it makes a huge difference.
I added required(this) at the end of the list as below:
"this", in that context, refers to the function, not the form. But since
you don't use the parameter, theres no point in adding it.
function checkValues() { if (! ( checkMonths() && checkTimes() && checkRoutes1() && checkAges() && checkGenders() && checkVars() && checkCauses() && checkPhases() && checkPersons() && checkFactors() && checkTypes() && checkErrors() && required(this) ) ) { return false; } }
I also tried it without the 'this' just in case.
Add some alerts in your functions to see where you are making it to so
that you can find out where its stopping.
In the body:
<FORM NAME="mainForm" onsubmit="retur n checkValues();" ACTION="readfil e.php" method="POST">
Thanks again for your help!
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Randy Webb said: kdc wrote: Thanks to both of you for your quick feedback. This is what I added to my program:
function required(mainfo rm){ var alertMessage = ''; if (' '==mainform.sub 1.value ){alertMessage += "Name Required\n";}
You are checking to see if sub1 is a space, not what you wanted.
if (' '==mainform.sub 2.value){alertM essage += " Position Required\n";}
Same there.
if (''==mainform.s ub3.value){aler tMessage += "Email Required\n";} if (alertMessage == ''){return true;} else{alert(aler tMessage);retur n false;}
}
I wasn't sure whether to use =mainform or ==mainform so I also tried it with a single =. It continues to ignore it.
It should be a double ==. My original had the typo in it and got propogated by me copy/pasting it.
I don't want to waste your time so let me ask if the fact that I call the function by adding it to another function (checkValues) that is then called in upon submission matters.
Yes, it makes a huge difference.
I added required(this) at the end of the list as below:
"this", in that context, refers to the function, not the form. But since you don't use the parameter, theres no point in adding it.
The argument to required() *is* being used as a reference to the form.
Changing "required(this) " to "required(docum ent.mainform)" looks like
the easiest way to fix it.
kdc wrote: Thanks to both of you for your quick feedback. This is what I added to my program:
function required(mainfo rm){ var alertMessage = '';
^^^[1] if (' '==mainform.sub 1.value ){alertMessage += "Name Required\n";}
^^^ ^^^^^^^^^^^^^[4] ^^[3] if (' '==mainform.sub 2.value){alertM essage += " Position Required\n";}
^^^^^^^^^^^^^[4] ^^[3] if (''==mainform.s ub3.value){aler tMessage += "Email Required\n";}
^^^^^^^^^^^^^[4] ^^[3] if (alertMessage == ''){return true;}
^^^^^[3] else{alert(aler tMessage);retur n false;}
}
Which is not only badly formatted and thus hardly legible[1], but will
also allow users to enter empty strings and strings consisting of two
or more spaces or other whitespace in some input elements[2] while
being inefficient[3] and not using standards compliant referencing[4].
Therefore, it should instead read
function required(mainfo rm)
{
var
rxEmpty = new RegExp("^\\s*$" ),
es = mainform.elemen ts,
alertMessage = new Array();
if (rxEmpty.test(e s["sub1"].value))
{
alertMessage.pu sh("Name Required");
}
if (rxEmpty.test(e s["sub2"].value))
{
alertMessage.pu sh("Position Required");
}
if (rxEmpty.test(e s["sub3"].value))
{
alertMessage.pu sh("Email Required");
}
return (alertMessage.l ength == 0 || !!alert(alertMe ssage.join("\n" ));
}
I wasn't sure whether to use =mainform or ==mainform so I also tried it with a single =. It continues to ignore it.
It is not ignored but as you try to assign (`=') something to a (string)
literal (' ' and ''), it causes a script error; with my UA:
| SyntaxError: invalid assignment left-hand side
But you have obviously either disabled the display of script errors or not
had a look into the UA's JavaScript console.
I don't want to waste your time [...]
Great. Why do you not read then previous discussions on the subject before
you post?
PointedEars This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jesper Stocholm |
last post by:
I have implemented role-based security within my ASP.Net application.
However, it seems the role is not passed to the authentication ticket I
create.
I want to use it to display/hide some content based on the user's role. I
wrote this to do it:
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
plLoggedIn.Visible = true;
|
by: Michelle Stone |
last post by:
Hi everybody
I am writing a simple asp.net application using form
authentication. I store the list of all users and their
passwords in an SQL Server database table.
My client recently told me that he wants me to do
something through which only one user can login using any
given account name. I mean to say, for example, when a
user called "abc" is online, another person shouldn't be
|
by: Shourie |
last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.
1) MainPage_load
2) User control1_Load
user clicks a dropdown in UC1
_________________________
1) MainPage_Load
2) User Control_1 Load
|
by: Jiho Han |
last post by:
Should ASPNET user belong to the local Users group?
I may have made some changes that affected my workstation setup and I am
experiencing some unexpected behaviors.
For example, I have my IIS set up with anonymous login and have ASP.NET
running.
My ASP.NET application then creates a log file and writes to it during its
course. The only thing is that it should not be able to.
My questions are below. Please correct any incorrect...
|
by: Guadala Harry |
last post by:
Is there any way for one Session to remove and update objects in another
Session? I seriously doubt it, but thought I'd ask. Here's why: I have some
data that is unique per user (or per session - similar to "welcome back,
Jim" after Jim logs in) and consumed across multiple pages. This "per user"
data lives in a database, so toward improving runtime performance I want to
cache data supporting this and similar per user features. Because the...
| |
by: Alphonse Giambrone |
last post by:
I am building a web app for users to add/edit data. They may add/edit
several records during a session.
When they are done (not necessarily immediately, could be 10 or more minutes
later), I need to send an email with some summary info of what was
added/edited.
I can keep track of the records by using the sessionid or user's login, but
how can I determine when to send the email and who the user was since there
is no session info available...
|
by: Michael |
last post by:
I have setup a public variable in the Master Page "code-behind-file". Now I
would like to set that value from the UserControl, but I can't seem to find a
way to do this. Does anyone have any ideas? I'm basically trying to set it up
so that I can keep the User infor (userid, ect) in the Masterpage so that
other pages can access it. Thanks for any ideas.
Michael
|
by: Carlettus |
last post by:
Dear All,
sorry but I'm not sure if this is the right place to post my problem.
I was using the following asp code to create users in Active Directory.
Suddenly, and I don't know the reason, users are created but the account is
disabled (see the flag User.AccountDisabled = False ).
There is also another problem even if the user does not exist , the
application returns to me with the message that the user already exist.
Thank you for...
|
by: rbukkara |
last post by:
Hi,
I have got the following error while trying to add a user in the LDAP Directory.
javax.naming.NameNotFoundException: ; remaining name 'uid=vassila,ou=People,dc=cs,dc=uno,dc=edu'
I have given all the attributes which are needed, for the user, in the code and also the proper path where the user has to be added. Please have a look at my code
CODE]
// This is a class file which stores all the info required for the user
|
by: shapper |
last post by:
Hello,
On my web site I have a property, Visitor, which is available for
Anonymous users:
public class Visitor {
public CultureInfo Culture { get; set; }
public List<GuidPolls { get; set; }
}
|
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...
| |
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,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |