473,386 Members | 1,706 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,386 software developers and data experts.

Unable to load javascrip

It seems that this script wont run, any idea what I have don wrong+

Code-----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
<!--
function isblank(s) {
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}

function SetRegAction() {

// WebBrukerID
if (isblank(document.form1.test.value)) {
alert ("Fornavn må fylles ut.");
document.form1.test.focus();
return (false);
}
//-->
</script>
</head>

<body>
<form name="form1" method="post" action="" onsubmit="javascript:return
SetRegAction()">
<input name="test" type="text" id="test">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
Jul 23 '05 #1
5 2341
Problemo solved, it was the missing "}" aarghhh
Terje

"Terje Sæternes" <te***@cyberfactory.no> skrev i melding
news:Tf********************@news000.worldonline.dk ...
It seems that this script wont run, any idea what I have don wrong+

Code-----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
<!--
function isblank(s) {
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}

function SetRegAction() {

// WebBrukerID
if (isblank(document.form1.test.value)) {
alert ("Fornavn må fylles ut.");
document.form1.test.focus();
return (false);
}
//-->
</script>
</head>

<body>
<form name="form1" method="post" action="" onsubmit="javascript:return
SetRegAction()">
<input name="test" type="text" id="test">
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>

Jul 23 '05 #2
Terje Sæternes wrote:
It seems that this script wont run, any idea what I have don wrong+ BE a bit more meaningful.
<form name="form1" method="post" action="" onsubmit="javascript:return
SetRegAction()">


take that javascript: away.
Put some alert boxes in SetRegAction() and you will see it works.
Jul 23 '05 #3
Terje Sæternes wrote:
Problemo solved, it was the missing "}" aarghhh


befoer you will ask next many questions here, try to figure it out by
yourself first in hours. You posted a message and after 5 minutes you
had found the answer. Youd better had cancelled the message.
Jul 23 '05 #4
On Fri, 29 Oct 2004 13:58:49 +0200, Terje Sæternes <te***@cyberfactory.no>
wrote:

[snip]
<script language="javascript" type="text/javascript">
The language attribute is deprecated, and the (required) type attribute
makes it redundant. Remove it.
<!--
Hiding SCRIPT element content is an obsolete practice. All user agents now
in use understand what a SCRIPT element is, even if they cannot execute
it. Scripts should usually be placed in external files anyway, hiding the
script automatically.
function isblank(s) {
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}
This is a really inefficient way of performing this sort of test. Use a
regular expression:

function isBlank(v) {
return /^\s*$/.test(v);
}

The regular expression will match any string that is either empty, or
solely composed of whitespace characters[1].
function SetRegAction() {
Submission handlers should generally be written to take one argument: a
reference to the form. This means you don't have to hard-code the form
name.

function SetRegAction(form) {
// ...

You'd call this from the FORM with:

<form ... onsubmit="SetRegAction(this);">

Note that you don't need "javascript:". It only makes a difference in one
browser (IE), and even then, its only necessary if you've been using
scripting languages other than Javascript. Most browsers will see that
string a label, and ignore it.

Based on this change, you could modify the following to:

// Save a reference to the 'test' control
var test = form.elements['test'];
if (isblank(document.form1.test.value)) {
if(isBlank(test.value)) {
alert ("Fornavn må fylles ut.");
document.form1.test.focus();
test.focus();
return (false);
return false;

The parentheses aren't necessary.
}
[snip]
<form name="form1" method="post" action=""
Now you don't need to name the form (you should use better names, anyway).
onsubmit="javascript:return SetRegAction()">
<input name="test" type="text" id="test">
You do realise that this control wouldn't be submitted, don't you?
<input type="submit" name="Submit" value="Submit">


Unless you have multiple submit buttons which represent different actions,
you generally don't need to name them. In such situations, something like:

<input type="submit" name="operation" value="Delete">

would be more appropriate. Certainly be careful not to use names that are
properties of the FORM object. Naming a control, action, for example, will
prevent you from accessing the action property on the FORM.

[snip]

Hope that helps,
Mike
[1] A more thorough explanation:

Regular expressions are composed of a series of productions that form a
pattern. Certain characters have special meanings, causing the pattern to
evaluated in a certain way. In the expression I used, there are four
tokens, each of which is special.

The first, ^, means that the pattern that follows must match the beginning
of the input. So, for example, ^some would match any string that began
with "some"; "something", "sometime", "some chicken", etc.

The last, $, means that the pattern that precedes the token must match the
end of the input.

The escape sequence, \s, matches whitespace characters.

The token, *, is a quantity specifier that means the preceding token can
exist zero or more times.

All together, you get a pattern that will match an empty string, or one
which contains only whitespace.

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5
"Terje Sæternes" wrote:
It seems that this script wont run, any idea what I have don wrong+

Code-----
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="javascript" type="text/javascript">
<script type="text/javascript">

The -language- attribute is deprecated and not required.
<!--
Not needed. Remove.
function isblank(s) {
for (var i = 0; i < s.length; i++) {
var c = s.charAt(i);
if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
}
return true;
}

function SetRegAction() {

// WebBrukerID
if (isblank(document.form1.test.value)) {
alert ("Fornavn må fylles ut.");
document.form1.test.focus();
return (false);
}
You're missing a closing -}- here.
//-->
Not needed. Remove.
</script>
</head>

<body>
<form name="form1" method="post" action="" onsubmit="javascript:return
SetRegAction()">
onsubmit="return SetRegAction();"
<input name="test" type="text" id="test">
<input type="submit" name="Submit" value="Submit">
This is fine, you've named your submit button "Submit". Be careful though,
if you named your submit button "submit" (note the lower case 's') you could
run into problems later if you attempt to submit the form programmatically
(ie - document.forms['theForm'].submit()).
</form>
</body>
</html>


--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #6

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

Similar topics

19
by: Nancy | last post by:
Hi, When I start my PC(winXP Pro), it always says: Unknown(): Unable toload dynamic library './php_msql.dll' - The specified module could not be found. Then my Apache servre starts, load php...
2
by: Carlos G Benevides | last post by:
I have a ASP.Net web application that has two assemblies that run under com+. Under Windows 2000 the two assemblies are added to com+ automatically when instantiated from the web site. For this...
3
by: StephenRichter | last post by:
I have installed the trial of db2 enterprise server on my w2k PC. Have also installed fix pack 8 of that product. I am using it to connect from an asp.net web page to an IBM as400. the 400 is...
2
by: MAF | last post by:
I am trying to use reflection to load an assembly and one of my assemblies throws the following error: One or more of the types in the assembly unable to load Is there anyway to find out...
1
by: ♥eXtreme oXygen♥ | last post by:
How do i call JAVASCRIP function from an event of ASP.NET:BUTTON, if runat=server attribute is true... actually i want to open an popup window using asp.net--button onclick event, but its not...
3
by: Axel Gallus | last post by:
Is there a way in javascrip, to load the html-code of a webpage like www.amazon.com into a string? E.g. string htmlcode = load_into_string( www.amazon.com); Thx in advance A.Gallus
3
by: Brett Wesoloski | last post by:
I can not seem to figure this out, but really haven't work a lot with javascrip and .NET. I have a data grid and I want to put a button in it and when the button is pressed it will call my...
0
by: wildman | last post by:
Trying to read XML files from SSIS and load into SQL Server. I tested this before and it was working before I placed in a forevery contrainer. also, my simple xml file had to be retyped cause I...
3
by: =?Utf-8?B?TGV3aXMgTW90ZW4=?= | last post by:
Hello. We are having a problem here trying to compile C# applications. Only one developer has a problem where they attempt to compile the application and the compiler complains about being out of...
1
by: lathamoulali | last post by:
Hello Frnds, I am new to the ASP.NET Programming.Please help me out with this problem. I have a page_load() method in which i have to invoke the javascrip's alert method.I am using inline...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
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,...

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.