Help with basics (newbie)

A

altergothen

Please help with this basic function - I get an error saying " Object
expected on Line 17"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Basic if else</title>
<script language="JavaScript">
var teststring;
function myregex(teststring){
if(teststring=="test"){
alert("Match found! in " + teststring);
} else {
alert("No match found in " + teststring);
}
</script>
</head>

<body>
<form>
<input type="button" value="click me" onClick="myregex('test')">
</form>
</body>
</html>
 
I

Ivo

Please help with this basic function - I get an error saying " Object
expected on Line 17"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Basic if else</title>
<script language="JavaScript">
var teststring;
function myregex(teststring){
if(teststring=="test"){
alert("Match found! in " + teststring);
} else {
alert("No match found in " + teststring);
}

Add another } here and the script will work.
HTH
Ivo
 
D

DrewM

altergothen said:
Please help with this basic function - I get an error saying " Object
expected on Line 17"

<script language="JavaScript">
var teststring;
function myregex(teststring){
if(teststring=="test"){
alert("Match found! in " + teststring);
} else {
alert("No match found in " + teststring);
}
</script>

Your function is missing a closing brace '}'.

Tip: download a Mozilla browser (I recommend Firefox) if you don't
already have one. They have a useful JavaScript Console that will give
more helpful error messages than IE. I bet it would've said something
like "Expected: } at line xx".

btw, any reason why 'teststring' is declared as a global outside of your
function?

drew.
 
R

Ron

DrewM said:
...Tip: download a Mozilla browser (I recommend Firefox) if you don't
already have one. They have a useful JavaScript Console that will give
more helpful error messages than IE....

Definitely download Mozilla if you're into web development. IE's
javascript console is as useful during errors as reporting "There's
javascript on this page". :p
 
I

Ivo

"Ron" said:
Definitely download Mozilla if you're into web development. IE's
javascript console is as useful during errors as reporting "There's
javascript on this page". :p

Well that at least will tell you javascript is recognized as such. That
Mozilla debugger is often worse than what it tries to cure.
Ivo
 
T

Tia

I strongly disagree. I use Mozilla Firefox 0.8 to test and debug web apps. I
find the Javascript console more helpful than anything the M$ debugger has
ever shown me. Faster and easier to use, more likely to give you the *real*
problem.
 
G

Geir Eivind Mork

Tia said:
I strongly disagree. I use Mozilla Firefox 0.8 to test and debug
web pps. I find the Javascript console more helpful than anything
the M$ debugger has ever shown me. Faster and easier to use, more
likely to give you the *real* problem.

Get Mozilla and try wenkman. That's a javascript debugger. :) Javascript
console is nice as well.

IE for javascript debugging isn't a fun ride. I always use Mozilla for
that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Help with code 0
Help with my responsive home page 2
Help with Visual Lightbox: Scripts 2
Need help with stripe payment 0
Help with some CSS 2
Please Help? 0
Help :( 3
In javascript, XML File Create, File Save 2

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top