473,698 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help solving select list javascript error

Hi,

I have the following code:

<FORM>
<font size="3">Brands </font><br />
<SELECT SIZE="1" NAME="categoryl ist" STYLE="font-size: 8pt">
<OPTION VALUE=http://my.domain,.com/cetegory1.html selected>Catego ry
1</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory2.html> Category
2</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory3.html> Category
3</OPTION>
</SELECT>
<a href="javascrip t:;"
onclick="goto_C ategoryURL(this .form.categoryl ist)"><img border="0"
src="../images/mybutton.gif" align="absbotto m"></a>
</FORM>

When I click on the button, I am expecting to go to the URL of the currently
selected item in the select list. Instead, I am getting the following
script error:

"Error: this.form has no properties"

How can I make this code work please?

Thanks,
Don
Jul 23 '05 #1
5 3366

John wrote:
Hi,

I have the following code:

<FORM>
<font size="3">Brands </font><br />
<SELECT SIZE="1" NAME="categoryl ist" STYLE="font-size: 8pt">
<OPTION VALUE=http://my.domain,.com/cetegory1.html selected>Catego ry 1</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory2.html> Category
2</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory3.html> Category
3</OPTION>
</SELECT>
<a href="javascrip t:;"
onclick="goto_C ategoryURL(this .form.categoryl ist)"><img border="0"
src="../images/mybutton.gif" align="absbotto m"></a>
</FORM>

When I click on the button, I am expecting to go to the URL of the currently selected item in the select list. Instead, I am getting the following script error:

"Error: this.form has no properties"

How can I make this code work please?

Thanks,
Don


Were you calling that function from an event handler property of a form
element (Button.onclick , e.g.), 'this' would reference the element
object, and, as all form elements expose a .form property - to allow
easy referencing of the containing Form object - this.form.categ orylist
would point to the select (this.form.elem ents.categoryli st is more
precise). Since you're calling it from a link, however - a link isn't a
form element, no matter where you embed it - this' references the Link
object, and Link objects have no .form property.
Use an suitable absolute reference:

<a...onclick="g oto_CategoryURL (document.forms[0].elements.categ orylist)">

....or name the form & use that, or use an id with
..document.getE lementById, or
document.getEle mentsByTagName( 'form').item(0) , or...

R. C. will now correct me. #:=o

Jul 23 '05 #2
John wrote:
Hi,

I have the following code:

<FORM>
<font size="3">Brands </font><br />
<SELECT SIZE="1" NAME="categoryl ist" STYLE="font-size: 8pt">
<OPTION VALUE=http://my.domain,.com/cetegory1.html selected>Catego ry
1</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory2.html> Category
2</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory3.html> Category
3</OPTION>
</SELECT>
<a href="javascrip t:;"
onclick="goto_C ategoryURL(this .form.categoryl ist)"><img border="0"
src="../images/mybutton.gif" align="absbotto m"></a>
</FORM>

When I click on the button, I am expecting to go to the URL of the currently
selected item in the select list. Instead, I am getting the following
script error:

"Error: this.form has no properties"

How can I make this code work please?


Stop referring to "this.form" when the link has no form property for
this.form to resolve to. If you are dead set on making your page JS
dependent, then use a proper reference to the form:

First, where is goto_CategoryUR L() defined?

<form name="myForm" action="myForm. php">

<button onclick="goto_C ategoryURL('doc ument.myForm.ca tegorylist')">
Click me, in JS enabled browsers, to go to a URL
</button>

And then validate your HTML.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #3
RobB wrote:
John wrote:
Hi,

I have the following code:

<FORM>
<font size="3">Brands </font><br />
<SELECT SIZE="1" NAME="categoryl ist" STYLE="font-size: 8pt">
<OPTION VALUE=http://my.domain,.com/cetegory1.html


selected>Catego ry
1</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory2.html> Category
2</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory3.html> Category
3</OPTION>
</SELECT>
<a href="javascrip t:;"
onclick="goto _CategoryURL(th is.form.categor ylist)"><img border="0"
src="../images/mybutton.gif" align="absbotto m"></a>
</FORM>

When I click on the button, I am expecting to go to the URL of the


currently
selected item in the select list. Instead, I am getting the


following
script error:

"Error: this.form has no properties"

How can I make this code work please?

Thanks,
Don

Were you calling that function from an event handler property of a form
element (Button.onclick , e.g.), 'this' would reference the element
object, and, as all form elements expose a .form property - to allow
easy referencing of the containing Form object - this.form.categ orylist
would point to the select (this.form.elem ents.categoryli st is more
precise). Since you're calling it from a link, however - a link isn't a
form element, no matter where you embed it - this' references the Link
object, and Link objects have no .form property.
Use an suitable absolute reference:

<a...onclick="g oto_CategoryURL (document.forms[0].elements.categ orylist)">

....or name the form & use that, or use an id with
..document.getE lementById, or
document.getEle mentsByTagName( 'form').item(0) , or...

R. C. will now correct me. #:=o


Nah, RW will get there first :)

document.getEle mentsByTagName( 'form').item[0] maybe? Untested but it
seems that the gEBTN would return a collection so array syntax would
seem to be the most appropriate choice.

And even in contradiction to my own reply to this thread, the best
solution is a submit button and use onSubmit to navigate, cancel
submission, and then have server side code redirect based on the select
elements value. Then, it is not JS Dependent.
--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #4

Randy Webb wrote:
RobB wrote:
John wrote:
Hi,

I have the following code:

<FORM>
<font size="3">Brands </font><br />
<SELECT SIZE="1" NAME="categoryl ist" STYLE="font-size: 8pt">
<OPTION VALUE=http://my.domain,.com/cetegory1.html
selected>Catego ry
1</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory2.html> Category
2</OPTION>
<OPTION VALUE=http://my.domain,.com/cetegory3.html> Category
3</OPTION>
</SELECT>
<a href="javascrip t:;"
onclick="goto _CategoryURL(th is.form.categor ylist)"><img border="0"
src="../images/mybutton.gif" align="absbotto m"></a>
</FORM>

When I click on the button, I am expecting to go to the URL of the


currently
selected item in the select list. Instead, I am getting the


following
script error:

"Error: this.form has no properties"

How can I make this code work please?

Thanks,
Don

Were you calling that function from an event handler property of a form element (Button.onclick , e.g.), 'this' would reference the element
object, and, as all form elements expose a .form property - to allow easy referencing of the containing Form object - this.form.categ orylist would point to the select (this.form.elem ents.categoryli st is more
precise). Since you're calling it from a link, however - a link isn't a form element, no matter where you embed it - this' references the Link object, and Link objects have no .form property.
Use an suitable absolute reference:

<a...onclick="g oto_CategoryURL (document.forms[0].elements.categ orylist)">
....or name the form & use that, or use an id with
..document.getE lementById, or
document.getEle mentsByTagName( 'form').item(0) , or...

R. C. will now correct me. #:=o


Nah, RW will get there first :)


My Hero. #:-0
document.getEle mentsByTagName( 'form').item[0] maybe? Untested but it
seems that the gEBTN would return a collection so array syntax would
seem to be the most appropriate choice.


It does return a NodeList, with the usual .item() *method*.

document.getEle mentsByTagName( 'form')[0] is also suitable, I prefer the
encapsulation of the item() approach. Whatever that means.

Didn't test your solution - but doesn't a <button> element in a form
act as a submitter? Might be scripting a race condition there (whatever
that means).

cheers, Rob

Jul 23 '05 #5
RobB wrote:
Randy Webb wrote:
RobB wrote:

<--snip-->
R. C. will now correct me. #:=o

Nah, RW will get there first :)

My Hero. #:-0

document.getE lementsByTagNam e('form').item[0] maybe? Untested but it
seems that the gEBTN would return a collection so array syntax would
seem to be the most appropriate choice.

It does return a NodeList, with the usual .item() *method*.


Thats why I usually stick to the document.forms approach, doesn't give
me as many headaches :)

But, since its a nodelist with a method, then the array syntax doesn't
seem as obvious anymore.
document.getEle mentsByTagName( 'form')[0] is also suitable, I prefer the
encapsulation of the item() approach. Whatever that means.

Didn't test your solution - but doesn't a <button> element in a form
act as a submitter? Might be scripting a race condition there (whatever
that means).


Not sure :) But I had something like this in mind:

<form onsubmit="retur n someFunction()" action="somePag e.php" .....>

<input type="submit" value="Change Locations">

Where the someFunction() would return false to cancel the submit.

Then, the only time it gets submitted is non-JS. somePage.php would read
the selects value and set a Location.Header to correspond to it. Thus,
making it "work" for non-JS browsers.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Jul 23 '05 #6

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

Similar topics

4
4667
by: Pasquale | last post by:
Hello, I wondering if there is a way to dynamically update a select list with javascript from a database query without having to reload the page to update the list?
7
3609
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
7
2169
by: Stephen | last post by:
I have some code which I call from a custom validator however I seem to have got the logic wrong and im having trouble figuring out how to write my code to get things to work the way I require. Below is the script I currently use and what it does along with what I would like it to do. Can someone please help me work how I can fix this. <script> function ValidateDropDownOrCheckBox(sender, args) { if ( document.forms.DropDownList1.value...
23
2788
by: casper christensen | last post by:
Hi I run a directory, where programs are listed based on the number of clicks they have recieved. The program with most clicks are placed on top and so on. Now I would like people to be apple to place a link on there site so people can vote for their program, "ad a click". eg someone clicks the link on some page and it counts +1 click on my page. if some one clicks the link below it will count a click on my page.
0
5569
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted ******************************************************** For this teeny job, please refer to: http://feeds.reddit.com/feed/8fu/?o=25
16
2743
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on screen appearance of the Select List grows for the first 5 rows then the scroll bar appears if there's more). So far so good. . . The problem is that none of the rows I'm inserting appear on the screen until I have RETURNed from my function; so If...
4
3075
by: rajesh619 | last post by:
I'm new to programming. I have created a servlet which retrieves values from the database after a value is put into the HTML page to which it is attached. But during compilation, it shows two errors. Please help me in solving this error. import java.io.*; import java.util.Enumeration; import javax.servlet.*; import javax.servlet.http.*; import java.sql.*; import java.net.*;
1
1195
by: lxxslay3rxxl | last post by:
Let's say I haf 3 project that I wan to list, each project should have 1 value assign to it, but if i remove 1 of the value for 1 of the project, and i tried to list all 3 projects, I get this error: Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record. This is my code: <% call OpenDB() set rs = Server.CreateObject("ADODB.recordset") sql="SELECT * FROM project ORDER BY id"...
4
6330
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59 Notice: Undefined index: args in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92 Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_error.php on line 92
0
8680
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
9169
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
9030
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7738
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...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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
4371
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4622
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.