I am very new to java script. I am wanting to validate a form and I
cant seem to get one validation to work. The first two work, but the
thrid I want to have a max length of 30 and I cant ssem to figure out
how to do that. Please help!
var msg = "";
if(document.jobOpening.jobCity.value == ""){
msg = msg + "Please provide a Job City before submitting the form.";
alert(msg);
document.jobOpening.jobCity.focus();
return false;
}
if(document.jobOpening.jobCounty.value == ""){
msg = msg + "Please provide a Job County before submitting the
form.";
alert(msg);
document.jobOpening.jobCounty.focus();
return false;
}
if(document.jobOpening.jobName.value =="", "maxlen=30"){
msg = msg + "Please provide a Job Name Less than 30 Char. before
submitting the form.";
alert(msg);
document.jobOpening.jobName.focus();
return false;
} 8 1327 gr************@gmail.com said the following on 4/19/2006 4:28 PM: I am very new to java script. I am wanting to validate a form and I cant seem to get one validation to work. The first two work, but the thrid I want to have a max length of 30 and I cant ssem to figure out how to do that. Please help!
if(document.jobOpening.jobName.length>29)
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
I fooled around with it a bit more and came up with this.
function validateMe(){
var msg = "";
if(document.jobOpening.jobCity.value == ""){
msg = msg + "Please provide a Job City before submitting the form.";
alert(msg);
document.jobOpening.jobCity.focus();
return false;
}
if(document.jobOpening.jobCounty.value == ""){
msg = msg + "Please provide a Job County before submitting the
form.";
alert(msg);
document.jobOpening.jobCounty.focus();
return false;
}
if(document.jobOpening.jobName.value== ""){
msg = msg + "Please provide a Job Name before submitting the form.";
alert(msg);
document.jobOpening.jobName.focus();
return false;
}
if(document.jobOpening.jobName.value.length > 31){
msg = msg + "Please provide a Job Name less than 30 Char. before
submitting the form.";
alert(msg);
document.jobOpening.jobName.focus();
return false;
} gr************@gmail.com wrote on 19 apr 2006 in comp.lang.javascript : That does not work
Please quote what you are replying to.
If you want to post a followup via groups.google.com, don't use the
"Reply" link at the bottom of the article. Click on "show options" at the
top of the article, then click on the "Reply" at the bottom of the article
headers.
<http://www.safalra.com/special/googlegroupsreply/>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress) gr************@gmail.com said on 20/04/2006 7:09 AM AEST: I fooled around with it a bit more and came up with this.
Coding by trial and error is usually not the best methodology ;-)
[...]
Your original error was here:
if(document.jobOpening.jobName.value =="", "maxlen=30"){
------------------------------------------------^^^^^^^^^^^^^^^^
That is an invalid if statement.
if(document.jobOpening.jobName.value.length > 31){ msg = msg + "Please provide a Job Name less than 30 Char. before submitting the form.";
The message does not fit the test. The test allows up to and including
30 characters, the statement says less than 30 characters - which is it?
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ>
Your right I did not have the right Char. length I want it to have up
to but not exceeding 30 char. I did fix the problem thanks to all for
your insight
RobG wrote: gr************@gmail.com said on 20/04/2006 7:09 AM AEST: I fooled around with it a bit more and came up with this.
Coding by trial and error is usually not the best methodology ;-)
[...]
Your original error was here:
if(document.jobOpening.jobName.value =="", "maxlen=30"){ ------------------------------------------------^^^^^^^^^^^^^^^^
That is an invalid if statement.
if(document.jobOpening.jobName.value.length > 31){ msg = msg + "Please provide a Job Name less than 30 Char. before submitting the form.";
The message does not fit the test. The test allows up to and including 30 characters, the statement says less than 30 characters - which is it?
-- Rob Group FAQ: <URL:http://www.jibbering.com/FAQ>
RobG wrote: gr************@gmail.com said on 20/04/2006 7:09 AM AEST:
<snip> Your original error was here:
if(document.jobOpening.jobName.value =="", "maxlen=30"){ ----------------------------------------------^^^^^^^^^^^^^^^^
(As a point in passing, indicating sections in code as above is common
on Usenet but suffers from assumptions about the font in use to display
the message. If the viewer's character widths do not correspond with
writer's the indicator will not line up with the part of the statement
that is being pointed to. The usual convention is to write such
indicators in a fixed-width font as then the viewer is in a position to
re-produce the desired effect by switching to a fixed width font
themselves. Otherwise, it is largely a coincidence when the writer's
font corresponds sufficiently closely with the viewer's.)
That is an invalid if statement.
<snip>
Actually it is not an invalid statement. Javascript has a 'list'
operator (see ECMA 262, 3re Ed. Section 11.14), which forms an
expression out of a comma separated sequence of AssignmentExpressions,
the whole Expression evaluating as the value of the last item in this
list (though each item in the list is evaluated during the evaluation of
the whole expression). This leaves the above syntactically correct (so
as 'valid' as javascript gets), but always evaluating to the value of
the final string "maxlen=30", which type-converts to boolean true for
the evaluation of the - if - expression.
Richard.
Richard Cornford said on 20/04/2006 9:42 AM AEST: RobG wrote:
gr************@gmail.com said on 20/04/2006 7:09 AM AEST:
<snip>
Your original error was here:
if(document.jobOpening.jobName.value =="", "maxlen=30"){ ----------------------------------------------^^^^^^^^^^^^^^^^
(As a point in passing, indicating sections in code as above is common on Usenet but suffers from assumptions about the font in use to display the message. If the viewer's character widths do not correspond with writer's the indicator will not line up with the part of the statement that is being pointed to. The usual convention is to write such indicators in a fixed-width font as then the viewer is in a position to re-produce the desired effect by switching to a fixed width font themselves. Otherwise, it is largely a coincidence when the writer's font corresponds sufficiently closely with the viewer's.)
I copy/pasted a tab character that was in the original post for
indenting. On posting, that was converted to spaces so the highlight no
longer aligned with text. Not an excuse, just an explanation. That is an invalid if statement.
<snip>
Actually it is not an invalid statement. Javascript has a 'list' operator (see ECMA 262, 3re Ed. Section 11.14), which forms an expression out of a comma separated sequence of AssignmentExpressions, the whole Expression evaluating as the value of the last item in this list (though each item in the list is evaluated during the evaluation of the whole expression). This leaves the above syntactically correct (so as 'valid' as javascript gets), but always evaluating to the value of the final string "maxlen=30", which type-converts to boolean true for the evaluation of the - if - expression.
Thanks - now I have another obfuscation tool up my sleeve :-o.
--
Rob
Group FAQ: <URL:http://www.jibbering.com/FAQ> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: MDOPro |
last post by:
A pal needs help on this site
greetings fellow newsgroupers. I recently found a site called Microsoft
Forums. In a very short time I became very known to the site and its an
excellent tool....
|
by: Patrick Parks |
last post by:
hi guys, i am trying to read in CD info from a file and put it into an
array, using a CD class. I have been working here for about 6-8 hours
trying to get the input file into an array. i just need...
|
by: Bob Alston |
last post by:
I am looking for any Microsoft Access based software that could be used
for a United Way agency that provides basic needs assistance - food,
clothing, financial (rent, utilities, Rx, gasoline,...
|
by: vib |
last post by:
Hi there,
I am looking at this code for quite awhile, still don't any clue why
one wants to do it this way. It is about display message through UART
or COM port. Here is the code.
The calling...
|
by: sgMuser |
last post by:
Hi,
I am not a good developer of Javascript codes. Needs this help to make
some modification to this famous free javascript from Anarchos. i am
using this in one of my webpage. What it does is,...
|
by: Xah Lee |
last post by:
Software Needs Philosophers
by Steve Yegge, 2006-04-15.
Software needs philosophers.
This thought has been nagging at me for a year now, and recently it's
been growing like a tumor. One...
|
by: hpbutterbeer |
last post by:
We have a Machine Project and my brain is currently in a clouded state. Sorry, I'm just a beginner in C Programming...
Text twist is a windows game whose main objective is to form words out of the...
|
by: casper christensen |
last post by:
Hi
I run a directory, where programs are listed based on the number of
clicks they have recieved. The program with most clicks are placed on
top and so on. Now I would like people to be apple to...
|
by: stargate03 |
last post by:
Hi there
I have a MYSQL database which has the following table
CREATE TABLE `#__content` (
`id` int(11) unsigned NOT NULL auto_increment,
`title` varchar(100) NOT NULL default '',
...
|
by: colleen1980 |
last post by:
Hi: I am trying to pull all the values from the listbox. But the ASP
code shows only the last record. Needs help
HTML
<html>
<head>
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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: 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...
|
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,...
|
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...
|
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...
| |