SEO Forums: Your seo discussion forum  
Welcome, Unregistered.
You last visited: Today at 03:00 PM
Tags:



Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-27-2008, 07:23 AM
html
Guest
 
Posts: n/a
Default select?



I have a select tag as follows

<SELECT ID="Select1" NAME="Select1" ONCHANGE="do_alert()">
<OPTION>1</OPTION>
<OPTION>2</OPTION>
</SELECT>

I need, when the user choose an option, to print an alert
which displays the text in the option chosen, i.e. 1 or 2
in this example, but how do I access the value of the html
select tag, I tried

alert(document.getElementById('Select1').value);

But this seems to be an empty alert box. Any ideas what might I be
doing wrong?

Tia




Reply With Quote


  #2 (permalink)  
Old 09-27-2008, 07:23 AM
Joost Diepenmaat
Guest
 
Posts: n/a
Default Re: select?

"html" <html@html.com> writes:

> I have a select tag as follows
>
> <SELECT ID="Select1" NAME="Select1" ONCHANGE="do_alert()">
> <OPTION>1</OPTION>
> <OPTION>2</OPTION>
> </SELECT>
>
> I need, when the user choose an option, to print an alert
> which displays the text in the option chosen, i.e. 1 or 2
> in this example, but how do I access the value of the html
> select tag, I tried
>
> alert(document.getElementById('Select1').value);
>
> But this seems to be an empty alert box. Any ideas what might I be
> doing wrong?


<select onchange="alert(this.elements[this.selectedIndex].value)">


--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Reply With Quote


  #3 (permalink)  
Old 09-27-2008, 07:23 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: select?

Joost Diepenmaat wrote:
> <select onchange="alert(this.elements[this.selectedIndex].value)">


<select onchange="window.alert(this.options[this.selectedIndex].value)">

And it is a bad idea regarding accessibility.


PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Reply With Quote


  #4 (permalink)  
Old 09-27-2008, 07:23 AM
Conrad Lender
Guest
 
Posts: n/a
Default Re: select?

On 2008-09-26 23:54, Thomas 'PointedEars' Lahn wrote:
> Joost Diepenmaat wrote:
>> <select onchange="alert(this.elements[this.selectedIndex].value)">

>
> <select onchange="window.alert(this.options[this.selectedIndex].value)">


So, have you found a browser yet where the global object isn't window?
I remember a thread where you said that just because nobody has ever
seen such a browser, it didn't mean we couldn't just write "alert"
instead of "window.alert".

Just asking.


- Conrad


PS: Agree about this.*options* and accessibility (in some cases),
of course.

PPS: I could go looking for that thread but right now I CBA :-)
Reply With Quote


  #5 (permalink)  
Old 09-27-2008, 07:23 AM
Conrad Lender
Guest
 
Posts: n/a
Default Re: select?

On 2008-09-27 00:09, Conrad Lender wrote:
> it didn't mean we couldn't just write


That should have been "could", obviously.
Too many negatives.

Conrad chart (empirical):

| ++ **
| ++ *+ *
| +++ ** + *
|+++**** + *
| ++ *
| ++*+++++++++++++++++++++
+------------------*---------------------
* number of beers ->
*
+ coding prowess
* language management

Sorry =)


- Conrad
Reply With Quote


  #6 (permalink)  
Old 09-27-2008, 07:23 AM
Joost Diepenmaat
Guest
 
Posts: n/a
Default Re: select?

Thomas 'PointedEars' Lahn <PointedEars@web.de> writes:

> Joost Diepenmaat wrote:
>> <select onchange="alert(this.elements[this.selectedIndex].value)">

>
> <select onchange="window.alert(this.options[this.selectedIndex].value)">
>
> And it is a bad idea regarding accessibility.


Of course it is.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Reply With Quote


  #7 (permalink)  
Old 09-27-2008, 07:23 AM
html
Guest
 
Posts: n/a
Default Re: select?

hi, thanks it works, my confusion arose due to the fact that
selectedIndex was missing from the intelisense of vs7.1,
also "this" doesn't work with intelisense.
thanks.


Reply With Quote


  #8 (permalink)  
Old 09-27-2008, 07:23 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default Re: select?

Conrad Lender wrote:
> On 2008-09-26 23:54, Thomas 'PointedEars' Lahn wrote:
>> Joost Diepenmaat wrote:
>>> <select onchange="alert(this.elements[this.selectedIndex].value)">

>> <select onchange="window.alert(this.options[this.selectedIndex].value)">

>
> So, have you found a browser yet where the global object isn't window?


Have you found a language reference that states alert() is a method of the
ECMAScript Global Object instead of Window host objects?

> I remember a thread where you said that just because nobody has ever
> seen such a browser, it didn't mean we couldn't just write "alert"
> instead of "window.alert".


You remember incorrectly. I am pretty sure I did point out on more than one
occasion that assuming that the ECMAScript Global Object had an alert()
method was error-prone, since Netscape JavaScript 1.0 already defined it to
be a method of Window objects, and the `window' property of the Global
Object to refer to such an object.

> Just asking.


Just replying.

> [...]
> PPS: I could go looking for that thread but right now I CBA :-)

^^^
Unfortunately, I am not familiar with that abbreviation and STFW was
inconclusive so far. What does it mean?


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
Reply With Quote


  #9 (permalink)  
Old 09-27-2008, 07:23 AM
dhtml
Guest
 
Posts: n/a
Default Re: select?

Thomas 'PointedEars' Lahn wrote:
> Conrad Lender wrote:
>> On 2008-09-26 23:54, Thomas 'PointedEars' Lahn wrote:
>>> Joost Diepenmaat wrote:


>
> You remember incorrectly. I am pretty sure I did point out on more than one
> occasion that assuming that the ECMAScript Global Object had an alert()
> method was error-prone, since Netscape JavaScript 1.0 already defined it to
> be a method of Window objects, and the `window' property of the Global
> Object to refer to such an object.
>


Can you provide an example of the error?


>
> PointedEars

Reply With Quote


  #10 (permalink)  
Old 09-27-2008, 07:23 AM
Conrad Lender
Guest
 
Posts: n/a
Default Re: select?

On 2008-09-27 00:54, Thomas 'PointedEars' Lahn wrote:
>> So, have you found a browser yet where the global object isn't window?

>
> Have you found a language reference that states alert() is a method of the
> ECMAScript Global Object instead of Window host objects?


Well that's the crux. Language references are fine (holy even, for some
people), but the real world is a mess. It doesn't matter if I do or do
not find a reference, when for all practical purposes, in all browsers
that anyone has cared to test, alert is window.alert. But see below.

I still refuse to use 'window.alert' until I'm shown one single instance
where a simple 'alert' doesn't work as expected. I'm barring
redefinitions of alert here, of course, just as you're barring
redefinitions of window.

>> I remember a thread where you said that just because nobody has ever
>> seen such a browser, it didn't mean we couldn't just write "alert"
>> instead of "window.alert".

>
> You remember incorrectly. I am pretty sure I did point out on more than one
> occasion that assuming that the ECMAScript Global Object had an alert()
> method was error-prone, since Netscape JavaScript 1.0 already defined it to
> be a method of Window objects, and the `window' property of the Global
> Object to refer to such an object.


Now I had to look it up, it was only a month ago after all. It was an
interesting thread, which is probably why I immediately thought of it
when you wrote "window.alert"., although towards the end it was mostly
people trying to convince each other of what "theory" means in a
scientific context (I'm afraid I disagree with you on that count again,
btw, but that's getting really off-topic, and I've had my share of
potential flame wars today). The "theory" being that there was no
browser in existance where 'window.alert' was not the same as 'alert'.

Here's the thread I'm referring to:
http://preview.tinyurl.com/4qrnqv

I'm not going to read that monster again tonight (CBA, see below ;-),
but what it came down to were mostly exchanges like this one:

[Jeremy J Starcher]
| >> In most major browsers, "window" refers to the global object,
| >> unless overridden.
|
[Thomas 'PointedEars' Lahn]
| > No, in *some* browsers it *appears* as if that were the case.
| > However, it was overlooked that a host object includes the
| > possibility to let it appear so.

And so on. I'm sure that you know the specs by heart, and can quote them
better than anyone else here. But theoretical possibilities aside, this
problem does not appear to exist in the real world. Yes I know, I state
this without having tested each and every instance out there. Still the
theory stands; and what else can we do than work with what we're given?

>> PPS: I could go looking for that thread but right now I CBA :-)

> ^^^
> Unfortunately, I am not familiar with that abbreviation and STFW was
> inconclusive so far. What does it mean?


Uh, I've sort of tried to avoid explicit profanity here... CBA is just
short for "can't be arsed". Don't get me wrong, I fucking love swearing,
but I usually try to be civilized in forums and groups.


- Conrad
Reply With Quote


Reply



Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On



All times are GMT. The time now is 03:00 PM.

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Great Seo Blog at SEONOTEPAD.COM