RobB wrote:
[color=blue]
> John wrote:
>[color=green]
>>Hi,
>>
>>I have the following code:
>>
>><FORM>
>> <font size="3">Brands </font><br />
>> <SELECT SIZE="1" NAME="categorylist" STYLE="font-size: 8pt">
>> <OPTION VALUE=http://my.domain,.com/cetegory1.html[/color]
>
> selected>Category
>[color=green]
>>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="javascript
:;"
>>onclick="goto_CategoryURL(this.form.categorylist )"><img border="0"
>>src="../images/mybutton.gif" align="absbottom"></a>
>></FORM>
>>
>>When I click on the button, I am expecting to go to the URL of the[/color]
>
> currently
>[color=green]
>>selected item in the select list. Instead, I am getting the[/color]
>
> following
>[color=green]
>>script error:
>>
>>"Error: this.form has no properties"
>>
>>How can I make this code work please?
>>
>>Thanks,
>>Don[/color]
>
>
> 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.categorylist
> would point to the select (this.form.elements.categorylist 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="goto_CategoryURL(document.forms[0].elements.categorylist)">
>
> ....or name the form & use that, or use an id with
> ..document.getElementById, or
> document.getElementsByTagName('form').item(0), or...
>
> R. C. will now correct me. #:=o
>[/color]
Nah, RW will get there first :)
document.getElementsByTagName('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.javascript FAQ -
http://jibbering.com/faq & newsgroup weekly