473,890 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

onchange is baffling me...

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=t hemes.php?schem e=(form.color_s chemes.options[form.color_sche mes.selectedInd ex].value)

My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='locat ion.href=themes .php?scheme=(fo rm.color_scheme s.options[form.color_sche mes.selectedInd ex].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
Jul 23 '05 #1
8 1983
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=t hemes.php?schem e=(form.color_s chemes.options[form.color_sche mes.selectedInd ex].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?sch eme=" 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
Jul 23 '05 #2
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?sche me=(form.color_ schemes.options[form.color_sche mes.selectedInd ex].value)

My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='loca tion.href=theme s.php?scheme=(f orm.color_schem es.options[form.color_sche mes.selectedInd ex].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='locat ion.href="theme s.php?scheme="+ form.color_sche mes.options[form.color_sche mes.selectedInd ex].value'

Jul 23 '05 #3
On Sun, 31 Oct 2004 19:07:33 GMT, Michelle <miki@spam_me.n et> wrote:

[snip]
<select name='scheme' size='1'
onchange='locat ion.href=themes .php?scheme=
(form.color_sch emes.options[form.color_sche mes.selectedInd ex].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.c om/groups?threadm= da7e68e8.040917 1356.25f6eca9%4 0posting.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.selectedIn dex].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(el em) {
location.href = 'themes.php?sch eme='
+ elem.options[elem.selectedIn dex].value;
}

<select ... onchange="chang eScheme(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.
Jul 23 '05 #4
Michelle <miki@spam_me.n et> 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?sche me=(form.color_ schemes.options[form.color_sche mes.selectedInd ex].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?sche me= to be a string.

Regards,
Steve
Jul 23 '05 #5
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?sch eme=(form.color _schemes.option s[form.color_sche mes.selectedInd ex].value)

My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='loc ation.href=them es.php?scheme=( form.color_sche mes.options[form.color_sche mes.selectedInd ex].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='locat ion.href="theme s.php?scheme="+ form.color_sche mes.options[form.color_sche mes.selectedInd ex].value'

Thank you all...such speedy replies...and now it works!!!
Jul 23 '05 #6
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?sch eme=(form.color _schemes.option s[form.color_sche mes.selectedInd ex].value)

My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='loc ation.href=them es.php?scheme=( form.color_sche mes.options[form.color_sche mes.selectedInd ex].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='locat ion.href="theme s.php?scheme="+ form.color_sche mes.options[form.color_sche mes.selectedInd ex].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
Jul 23 '05 #7
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=t hemes.php?schem e=(form.color_s chemes.options[form.color_sche mes.selectedInd ex].value)
My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='locat ion.href=themes .php?scheme=(fo rm.color_scheme s.options[form.color_sche mes.selectedInd ex].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
Jul 23 '05 #8
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=t hemes.php?schem e=(form.color_s chemes.options[form.color_sche mes.selectedInd ex].value)
My Code for the dropdown box is:
<form name='color_sch emes' method='post' action='themes. php' >
Select a scheme:&nbsp;
<select name='scheme' size='1'
onchange='locat ion.href=themes .php?scheme=(fo rm.color_scheme s.options[form.color_sche mes.selectedInd ex].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
Jul 23 '05 #9

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

Similar topics

5
4600
by: TimS | last post by:
I am getting a baffling File not found error (0x800A0035). I am writing asp on a windows 2000 server. I build a path and filename from several fields in a jet database using SQL commands, like this: Sql = "SELECT dirs.rootname,dirs.dirname FROM dirs" RS.open Sql RS.movefirst do while not RS.EOF temp1=trim(RS("rootname"))
2
570
by: Jeff | last post by:
Hi Everyone, I'm having a problem with onChange. The tag looks like: <input:text bean = "" name="X" label="Y" attributesText="onChange=\"clear()\""> </input:text> if i replace, onChange with onBLur, the call works. when i try using onchange without the attributesText it tells me onchange is not supported by the top level domain. if I change the start of the tag
2
12177
by: Asit | last post by:
In JavaScripts checks for an onChange event against the value of the textbox at the time of the last onChange event. Since an onChange Event never fired after you changed the text first time , suppose we put the same value in the text box then no event is fired. If we put some other value then it became fired... It wouldn't fire if we put the same value... I don't want to use onBlur etc... Isthere any solution with onChange Event...?
4
6143
by: Bart van Deenen | last post by:
Hi all I have a script where I dynamically create multiple inputs and selects from a script. The inputs and selects must have an associated onchange handler. I have the script working fine on Firefox, Safari and Konqueror, but the onchange event just doesn't fire on IE6. Firefox's javascript console shows no errors, and the IE script debugger shows nothing. onchange is not triggered.
5
14554
by: Good Man | last post by:
Hi there I'm adding form fields on the fly with some javascript DOM programming. I basically just clone a hidden <div>, then adjust node properties to make this new <div> have unique values (style, size, etc.) the original code of the input tag is: <input type="file" onchange="alert('original')" size="30" id="filea" name="filea">
3
3994
by: jab3 | last post by:
Hello. I"m new to this group, and to JavaScript in general, so please forgive me if I breach local etiquette. I'm trying to implement some client-side 'dynamic' validation on a form. I'm having a couple of problems, which I'll try to describe. But this e-mail will only reproduce one of them, in a "short" example. What I'm generally doing is having each form entry contained in a div, which as a label, an input with some event handlers,...
3
3919
by: b_naick | last post by:
I realize that the onChange event for a drop down can be trapped as follows: <select name="myDropDown" onChange="somefunc"> Is it possible to trap the onChange event outside of the select statement? Something like this: document.forms.myDropDown.onChange = somfunc;
21
29852
by: Leena P | last post by:
i want to basically take some information for the product and let the user enter the the material required to make this product 1.first page test.php which takes product code and displays prodcut anme have used ajax to avoid refreshing of page this works fine 2.now i have created one row with checkbox|select box|text|text|text|text| where in the select box values are fetched from table here also i have used ajax for getting the m_name...
0
9975
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9812
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11212
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10446
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7154
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6032
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4655
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4255
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.