Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > onchange is baffling me...

Reply
Thread Tools

onchange is baffling me...

 
 
Michelle
Guest
Posts: n/a
 
      10-31-2004
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_scheme s.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.co lor_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
 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      10-31-2004
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_schem es.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.c olor_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'

 
Reply With Quote
 
 
 
 
David Dorward
Guest
Posts: n/a
 
      10-31-2004
Michelle wrote:

> 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_scheme s.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 +.


--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
 
Reply With Quote
 
Michael Winter
Guest
Posts: n/a
 
      10-31-2004
On Sun, 31 Oct 2004 19:07:33 GMT, Michelle <miki@spam_me.net> wrote:

[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/groups?threadm=da7e68e8.0409171356.25f6eca9%40post ing.google.com>
<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;
}

<select ... onchange="changeScheme(this);">

> <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

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
 
Reply With Quote
 
Steve van Dongen
Guest
Posts: n/a
 
      10-31-2004
Michelle <miki@spam_me.net> wrote:

>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_schem es.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
 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      10-31-2004
Lee wrote:
> 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_sche mes.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!!!
 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      10-31-2004
Lee wrote:
> 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_sche mes.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
 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      10-31-2004
Michelle wrote:
> 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_scheme s.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.co lor_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
 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      10-31-2004
Michelle wrote:
> 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_scheme s.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.co lor_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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
v easy but baffling to me CSS question =?Utf-8?B?Q2hhcmxlc0E=?= ASP .Net 4 04-05-2006 03:20 PM
simple but baffling javascript prob =?Utf-8?B?Q2hhcmxlc0E=?= ASP .Net 2 03-22-2006 02:28 PM
Re: Baffling class not found problem laredotornado@zipmail.com Java 1 05-26-2005 04:56 PM
simply baffling DSL networking issue. see.cher@your.place Computer Support 5 12-17-2004 11:06 PM
Baffling question ASP .Net 4 11-09-2003 12:46 AM



Advertisments