Hello,
My hair falls out!
Is it possible to retrieve the "ordering value" of the <option> that
was clicked inside a range of options ?
In other words, with something like
<option value="myvalue" >mytext</option>
is it possible to know the position of that <option> between the other
<option>s and retrieve that value through javascript ?
Here is the simplified code, where "myvar" is the variable that should
somehow become the position of the clicked option:
<html>
<head>
<script>
function g(myvar)
{
alert('You clicked on the ' + myvar + 'th option.')
}
</script>
</head>
<body>
<select name="n" onChange="g(thi s.value)">
<option value="a">111
<option value="b">222
<option value="c">333
</select>
</body>
</html>
Many thanks
Bart 5 2578
"Bart Van der Donck" <ba**@nijlen.co m> schreef in bericht
news:b5******** *************** ***@posting.goo gle.com... Hello,
My hair falls out! Is it possible to retrieve the "ordering value" of the <option> that was clicked inside a range of options ? In other words, with something like <option value="myvalue" >mytext</option> is it possible to know the position of that <option> between the other <option>s and retrieve that value through javascript ?
Here is the simplified code, where "myvar" is the variable that should somehow become the position of the clicked option:
I think that you are looking for selectedIndex:
....
<script>
function g(myvar)
{
// selectedIndex starts off with 0, so add 1 to meet
// human logics
alert('You clicked on the ' + ++myvar + 'th option.')
}
</script>
</head>
<body>
<select name="n" onChange="g(sel ectedIndex)">
<option value="a">111
<option value="b">222
<option value="c">333
</select>
</body>
....
JW
Janwillem Borleffs wrote on 06 sep 2003 in comp.lang.javas cript: I think that you are looking for selectedIndex: ... <script> function g(myvar) { // selectedIndex starts off with 0, so add 1 to meet // human logics alert('You clicked on the ' + ++myvar + 'th option.') } </script> </head>
<body> <select name="n" onChange="g(sel ectedIndex)"> <option value="a">111 <option value="b">222 <option value="c">333 </select> </body>
IE:
<script>
function g(x,myvar) {
alert('the optionvalue was: ' + x.childNodes[myvar+1].value +
'\nthe text was: ' + x.childNodes[myvar+1].innerText)
}
</script>
<select name="n" onChange="g(thi s,selectedIndex )">
<option value="a">111
<option value="b">222
<option value="c">333
</select>
</body>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
"Evertjan." <ex************ **@interxnl.net > schreef in bericht
news:Xn******** ************@19 4.109.133.29... IE:
<script> function g(x,myvar) { alert('the optionvalue was: ' + x.childNodes[myvar+1].value + '\nthe text was: ' + x.childNodes[myvar+1].innerText) } </script>
Why using DOM when the Form object already provides you with cross-browser
compliant properties?
function g(x,myvar) {
alert('the optionvalue was: ' + x[myvar].value +'\nthe text was: ' +
x[myvar].text)
}
JW
Janwillem Borleffs wrote on 06 sep 2003 in comp.lang.javas cript: "Evertjan." <ex************ **@interxnl.net > schreef in bericht news:Xn******** ************@19 4.109.133.29... IE:
<script> function g(x,myvar) { alert('the optionvalue was: ' + x.childNodes[myvar+1].value + '\nthe text was: ' + x.childNodes[myvar+1].innerText) } </script> Why using DOM when the Form object already provides you with cross-browser compliant properties?
dunno
function g(x,myvar) { alert('the optionvalue was: ' + x[myvar].value +'\nthe text was: ' + x[myvar].text) }
didn't know about .text, tnx
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Thanks Janwillem & Evertjan,
Groetjes uit Belgie
Bart This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ang Talunin |
last post by:
Hey,
I wondering if it's possible to retrieve all the <option>-fields from a
<select> when posting a <form> to a php file
Example:
I've got a form like this:
<form action = phpfile.php method=post >
<select name= "name">
|
by: Hal Vaughan |
last post by:
I'm using KDE on Linux, with Konqueror as the testing browser for this
project. I've recently upgraded, so I realize some of the bugs I'm dealing
with may or may not be my program, and could also result from me being less
than perfect in my preliminary coding on test pages.
I had an <OPTION> element, 10 lines in size. Previously I used:
onclick="fillFields()"
and when I clicked on a line in the <OPTION> element, the data was
|
by: Chris Fink |
last post by:
Does anyone know it is possible to include a small image(.gif .jpeg)
within a <SELECT><option> so that the user would see the option text as
well as a little image(icon) in the option? I know this is not an ASP.NET
related question, but I know this group is knowledgeable and quick with
responses.
Thanks
|
by: joseph.lindley |
last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too
bad.
I'm currently working with a bit of javascript to dynamically add
<option>s into a select box. My code currently works fine in Internet
Explorer, however in Firefox the dropdown only displays the first
option in the list, and when clicked the other values aren't displayed.
Here is the code;
|
by: frey |
last post by:
i tried to create a dropdown menu and use the option as a control to
change content inside another text area
the code is like this:
<select name="xxxx"><option onclick="changeunitprice(29.87)"
value="1744"/>
the function changeunitprice() is called when an option is selected
| |
by: Man-wai Chang |
last post by:
--
iTech Consulting Co., Ltd.
Expert of ePOS solutions
Website: http://www.itech.com.hk (IE only)
Tel: (852)2325 3883 Fax: (852)2325 8288
|
by: pplers |
last post by:
Here is config.php:
<?php //The vars are all ok.
$dbhost = 'localhost';
$dbname = 'forum';
$dbuser = 'toor';
$dbpass = '';
?>
Here is a part of functions.php:
<? require "config.php"; //It is in the same directory.
|
by: The Natural Philosopher |
last post by:
This is a nasty one and I can't see my way out of it.
I have a bunch of select statements in a form, and each select statement
has an onchange="do_something(this)" in it, and this works
nicely..except when there is only ONE OPTION in a given select.
It seems you cannot 'onchange' a single option!
Well, that is reasonable.
The trouble is I have no way of selecting it since the form itself is a
|
by: eihabisaac |
last post by:
hey every body
how can i get using javascript the selected option <option> ID or Value because when ever i clicked it i get the <select> id and i dont want that
<select name="list" id="list" size="10%" >
<option id="3" ondblclick="select_song();">Apple
<br> </option>
<option id="4" ondblclick="select_song();">Orange
<br> </option>
<option id="5" ondblclick="select_song();">Banana<br> </option>
|
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...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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...
| |
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
| |