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

Can't Get Basic Script to Work

Hey,

I used to know javascript, but it's been years since I've used it. I'm
trying to relearn it, but I'm stuck already. Can anyone tell me why
this does nothing when I load the page?

Thanks
PulsarSL
---------

<html>
<head>

<script language="javascript">
function printTest()
{
alert("testing")
document.write("testing")
return()
}
</script>

</head>
<body onload="printTest()">

</body>
</html>

May 6 '06 #1
6 1303
Pu******@gmail.com wrote:
<script language="javascript">

Deprecated, use <script type="text/javascript"> instead.
return()


"return" is not a function, use it without the parenthesis.
JW
May 6 '06 #2
sorry but can i ask why
<scrip language="javascript"> is deprecated?
"Janwillem Borleffs" <jw@jwscripts.com> wrote in message
news:44***********************@news.euronet.nl...
Pu******@gmail.com wrote:
<script language="javascript">


Deprecated, use <script type="text/javascript"> instead.
return()


"return" is not a function, use it without the parenthesis.
JW

May 6 '06 #3
On 06/05/2006 07:55, jedikings wrote:
sorry but can i ask why
<scrip language="javascript"> is deprecated?


The value of the language attribute is an unstructured string, defined
by vendors. I would surmise that this was deemed undesirable, and that a
well-known format - MIME types, in this case - would be preferable.

There are also reasons to avoid specific values in the language
attribute, as described in the FAQ notes[1].
You're rather late to ask this question; the attribute was deprecated
around eight years ago.

[snipped top-post]

Please do not top-post and full-quote to this group.

How do I quote correctly in Usenet?
<http://www.netmeister.org/news/learn2quote2.html>

You might want to investigate OE-QuoteFix
(<http://home.in.tum.de/~jain/software/oe-quotefix/>).

Mike
[1] <http://www.jibbering.com/faq/faq_notes/script_tags.html#hsAtln>

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
May 6 '06 #4

Janwillem Borleffs wrote:
Pu******@gmail.com wrote:
<script language="javascript">


Deprecated, use <script type="text/javascript"> instead.
return()


"return" is not a function, use it without the parenthesis.


Thanks, this fixed it right up!

Wow -- I didn't realize it was deprecated so long ago. Very
interesting.

Thx,
PulsarSL

May 7 '06 #5
On 2006-05-07, Pu******@gmail.com <Pu******@gmail.com> wrote:

Janwillem Borleffs wrote:
Pu******@gmail.com wrote:
> <script language="javascript">
>


Deprecated, use <script type="text/javascript"> instead.
> return()
>


"return" is not a function, use it without the parenthesis.


While it is not a function (nor is "if") one can use parenthesis and
the white space between the word and the parenthesis does not matter.

if (x==4)

or

if(x==4)

seem to work with no problems as does:

function square(x) {
return x*x OR
return (x*x) OR
return(x*x) OR
}

But return is not a function (as was pointed out). The parentheses are not
part of "return" (as they are in a function's syntax, myfunction()) but
simply delimiters for the expression returned. If you use them it forces
Javascript to evaluate that expression. The expression () (what does that
evaluate to?) results in an error and the default (unless you use try/catch
to trap errors) is to stop at an error.
May 7 '06 #6
Spamless wrote:
On 2006-05-07, Pu******@gmail.com <Pu******@gmail.com> wrote:

Janwillem Borleffs wrote: <snip>
"return" is not a function, use it without the parenthesis.

While it is not a function (nor is "if") one can use parenthesis
and the white space between the word and the parenthesis does
not matter.

if (x==4)

or

if(x==4)


Generally javascript will allow any amount of white space to appear
between language tokens of any sort. There are some restrictions on the
contexts in which white space that is also a line terminator may appear,
But you could write your - if - statement as:-

if
(
x
==
4
)
{
...
}

- without causing any issues to the language interpreter (humans on the
other hand would tend to be unhappy to be asked to read it).
seem to work with no problems as does:

function square(x) {
return x*x OR
return (x*x) OR
return(x*x) OR
}

But return is not a function (as was pointed out).
The parentheses are not part of "return" (as they are in
a function's syntax, myfunction())
There is not really any "function's syntax, myfunction()". That is a
CallExpression, which is made up of two parts; a MemberExpression (or
another CallExpression) followed by an Arguments expression, where
Arguments are parentheses surrounding a possibly empty ArgumentsList.
This parenthesised Arguments expression can be regarded as an operator
that acts upon the MemberExpression as its operand; resolving the
MemberExpression as a function and calling it (passing any contained
arguments on to the call).
but simply delimiters for the expression returned.
Those parenthesise are not delimiters. They are actually an Expression
in their own right; a PrimaryExpression consisting of the parenthesise
sounding another Expression. This primary expression is evaluated at run
time, evaluating to the value of the result of the evaluation of the
Expression contained in the parenthesise. (Interpreter optimisations
should allow many parenthesised expressions to be silently removed and
replaced with the contained Expression, so they will not actually be
evaluated at run-time.)
If you use them it forces Javascript to evaluate that
expression.
The expression would be evaluated anyway. The parenthesise allow the
precise order of evaluation of a larger expression to be controlled, and
can be used to express the expected order of evaluation in the source
code (for clarity), or even to allow white-space free source code to be
unambiguously tokenised.
The expression ()
The only javascript production that allows that as an expression is
Arguments. It can only be interpreted as an attempt to call a
left-hand-side that is a function. The Expression in -
PrimaryExpression: ( Expression ) - is not optional.
(what does that evaluate to?) results in an error and
the default (unless you use try/catch to trap errors)
is to stop at an error.


Try-catch will not help at all in this context as Arguments following
the - return - keyword is a syntax error (return is not a
MemberExpression or a CallExpression). Syntax errors are triggered prior
to code execution and try-catch can only catch runtime errors (only the
use of - eval - or the Function constructor could produce a syntax error
at runtime and so be caught with try-catch).

Richard.
May 7 '06 #7

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

Similar topics

15
by: Simon | last post by:
I would like to create a very basic file upload add image form to add to my web site and to keep them in a "tmp" directory within my web hosting file manager once uploaded. I understand the basic...
2
by: David Pautler | last post by:
I'm creating a web-based authoring tool where one form encompasses several sections for editing. I'd like each section to have its own reset button, so that use of that button affects only that...
1
by: Tom Rahav | last post by:
Hello all! I develop application in Visual Basic .NET and ORACLE database. My question is how do I "send" script file to the database using visual basic .net. Other words, is there any way to...
2
by: duncan | last post by:
why does this work :- <HEAD> ...... <SCRIPT LANGUAGE="javascript"> function test() { alert("test 1") } </SCRIPT>
7
by: frustrated777 | last post by:
I'm new to mysql but seem to understand it enough to do what simple stuff I need but I can't get even this basic script to echo what is in the one colum, one row table. I am able to connect now it...
24
by: Paul | last post by:
I am taking over an existing app and having trouble understanding their references. They have encapsulated Pear packages in the directory structure like: /site /site/html/Pear.php...
20
by: Pete Marsh | last post by:
Wondering if anyone can see an error with this script. I get a server configuration error. THat could mean a module is not being loaded, but maybe there's a syntax error here, can anyone spot it?...
3
by: Gilles Ganault | last post by:
Hello I have a PHP script rss.php that serves RSS to clients. It work fine, but I'd like to server customized contents, and for this, I need to know who the user is. Unless there's a better...
19
RMWChaos
by: RMWChaos | last post by:
Previously, I had used independent JSON lists in my code, where the lists were part of separate scripts. Because this method did not support reuse of a script without modification, I decided to...
9
by: Matthew Wells | last post by:
OK, I've narrowed down the problem. This works when in the aspx page <script type="text/javascript" > function btnFirst_Click() { alert("Hello");...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: 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...

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.