onchange is baffling me...

M

Michelle

I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>
<option value =' 1'>Dark Gray background, Black fonts and Blue/Gray cell
colors</option>

<option value =' 2'>Dark Blue background, Black fonts and Blue/Gray cell
colors</option>
<option value =' 3'>Gray background, Black and Green fonts and Green
cell colors</option>
<option value =' 4'>Light Gray background, Dark Blue fonts and Cyan/Teal
cell colors</option>
<option value =' 5'>Light Gray background, Dark Blue fonts and Light
Blue cell colors</option>
<option value =' 6'>White background, Black fonts, Outset Borders and
Red/Rose menu headings</option>
<option value =' 7'>White background, Black fonts, Outset Borders and
Blue menu headings</option>
<option value =' 8'>White background, Black fonts and Blue/Light Gray
cell colors</option>

I would appreciate any advice...its probably something that is very
trivial and a very glaring defect, but I am blind to it.

Thanks,

Miki
 
L

Lee

Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>

That onchange value is not valid Javascript.
The right hand side of the (first) assignment operator contains a
question mark, so it looks like a conditional expression.
You really meant for it to be a string, so you should use quotes:

onchange='location.href="themes.php?scheme="+form.color_schemes.options[form.color_schemes.selectedIndex].value'
 
D

David Dorward

Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

It thinks you are trying to do:

variable = test ? result if true : (result if false)

For example:

var foo = document.forms['myForm'].elements['myCheckbox'].checked ?
"Wonderful" : "Terrible";

Which is shorthand for:

var foo;
if (document.forms['myForm'].elements['myCheckbox'].checked) {
foo = "Wonderful";
} else {
foo = "Terrible";
}

Of course, you aren't trying to do anything like that. Strings (like
"themes.php?scheme=" need to be quoted. To return the combination of a
string and the contents of a variable, use a +.
 
M

Michael Winter

[snip]
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=
(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>

There are four errors here:

1) Using a SELECT element to navigate to a different page when the value
is changed.

This technique is bad for usability. See:

<URL:http://groups.google.com/[email protected]>
<URL:http://www.cs.tut.fi/~jkorpela/forms/navmenu.html>

2) Not assigning a string.

The location.href property is a string, and expects a string to be
assigned to it.

themes.php

is not a string, so it will need to be quoted (along with the rest of the
literal text). In fact, the script parser will interpret that as the php
property of the object, themes (which of course, doesn't exist).

3) An unqualified reference.

It might not be wise to use

form.

to access the SELECT element's form property. Instead, use the this
operator to refer to the element and then its property:

this.form.

However, that should suggest that referencing the form property is
unnecessary, anyway.

this.options[this.selectedIndex].value

will do.

4) Accessing a non-existent control.

You don't have a form control called color_schemes. That's the name of
your form.

Once you combine those together, you'll have valid code. I've moved the
code into a function for clarity.

function changeScheme(elem) {
location.href = 'themes.php?scheme='
+ elem.options[elem.selectedIndex].value;
}

<option value =' 1'>

Even if you do go ahead with this approach - using a button instead of
onchange - you'll have to change these values. You can't have a space in
the URL.

[snip]

Mike
 
S

Steve van Dongen

Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

The syntax for the ?: operator is
(condition) ? (statement) : (statement)
and is the short form of
if (condition) { statement } else { statement }

Your code says to test whether the php property of the themes object
exists and is non-null/non-zero. If it is then set location.href to
the value of the dropdown list; if not... oops... there is no : with
an else clause.

You want themes.php?scheme= to be a string.

Regards,
Steve
 
M

Michelle

Lee said:
Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>


That onchange value is not valid Javascript.
The right hand side of the (first) assignment operator contains a
question mark, so it looks like a conditional expression.
You really meant for it to be a string, so you should use quotes:

onchange='location.href="themes.php?scheme="+form.color_schemes.options[form.color_schemes.selectedIndex].value'
Thank you all...such speedy replies...and now it works!!!
 
M

Michelle

Lee said:
Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)

My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>


That onchange value is not valid Javascript.
The right hand side of the (first) assignment operator contains a
question mark, so it looks like a conditional expression.
You really meant for it to be a string, so you should use quotes:

onchange='location.href="themes.php?scheme="+form.color_schemes.options[form.color_schemes.selectedIndex].value'
Thank you all...such speedy replies...and now it works!!!

But now I will also consider using a button to keep users from having

fits...

Miki
 
M

Michelle

Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)


My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>

<option value =' 1'>Dark Gray background, Black fonts and Blue/Gray cell
colors</option>

<option value =' 2'>Dark Blue background, Black fonts and Blue/Gray cell
colors</option>
<option value =' 3'>Gray background, Black and Green fonts and Green
cell colors</option>
<option value =' 4'>Light Gray background, Dark Blue fonts and Cyan/Teal
cell colors</option>
<option value =' 5'>Light Gray background, Dark Blue fonts and Light
Blue cell colors</option>
<option value =' 6'>White background, Black fonts, Outset Borders and
Red/Rose menu headings</option>
<option value =' 7'>White background, Black fonts, Outset Borders and
Blue menu headings</option>
<option value =' 8'>White background, Black fonts and Blue/Light Gray
cell colors</option>

I would appreciate any advice...its probably something that is very
trivial and a very glaring defect, but I am blind to it.

Thanks,

Miki
Thank you all...such speedy replies...and now it works!!!

But now I will also consider using a button to keep users from having

fits...

Miki
 
M

Michelle

Michelle said:
I have tried every variation of the "onchange" statement below without
any actual reloading of the page: The FireFox javaScript Console reports
the following message:

Error: missing : in conditional expression
Source Code:
location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)


My Code for the dropdown box is:
<form name='color_schemes' method='post' action='themes.php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='location.href=themes.php?scheme=(form.color_schemes.options[form.color_schemes.selectedIndex].value)'>

<option value =' 1'>Dark Gray background, Black fonts and Blue/Gray cell
colors</option>

<option value =' 2'>Dark Blue background, Black fonts and Blue/Gray cell
colors</option>
<option value =' 3'>Gray background, Black and Green fonts and Green
cell colors</option>
<option value =' 4'>Light Gray background, Dark Blue fonts and Cyan/Teal
cell colors</option>
<option value =' 5'>Light Gray background, Dark Blue fonts and Light
Blue cell colors</option>
<option value =' 6'>White background, Black fonts, Outset Borders and
Red/Rose menu headings</option>
<option value =' 7'>White background, Black fonts, Outset Borders and
Blue menu headings</option>
<option value =' 8'>White background, Black fonts and Blue/Light Gray
cell colors</option>

I would appreciate any advice...its probably something that is very
trivial and a very glaring defect, but I am blind to it.

Thanks,

Miki
Thank you all...such speedy replies...and now it works!!!

But now I will also consider using a button to keep users from having

fits...

Miki
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top