473,386 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

this.SelectedIndex does not work - why...?

Hi - I have a really stupid failure of code, can't figure it out.
Two fields in a form, Textinput and select; if text is written into
input, select changes "selected" to a matching option. This works.
Now I would like to put the WHOLE value of the selected option into
the input field, if the user klicks on something in the select-field.
This DOESN'T work, because I seem not to reference the selected item
correctly.
But then again i did everything according to the various tutorials.
THX for a quick hint.

Code:

___________________
<html>
<head>
<title>Some page</title>
<script language="JavaScript">
<!--javascript:
function selectOption(oTxt){
var sel = oTxt.form.select;
var len = sel.options.length;
sel.selectedIndex = len - 1; //select 'Select One' option by default
for (var i=0; i<len; i++){
if (sel.options[i].value.indexOf(oTxt.value)!=-1){
sel.selectedIndex = i;
break;
}
}
}
//--</script>

<script language="JavaScript">
<!--javascript:
function ChangeField (oTxt){
var stamm = oTxt.form.write;
var sel=oTxt.SelectedIndex;
stamm.value=oTxt.options[sel].value;

}
//--</script>

</head>

<body>
<form name="Anmeldung" method="post" action="anmelden.php">
<input type="text" name="write" size="23"
onkeyup="selectOption(this)" onblur="selectOption(this)" value="">

<select name="select" size="3" onclick="ChangeField(this)">
<option value="A name">A name</option>
<option value="B Name">B name</option>
<option value="C name">C name</option>
<option value="D name">D name</option>
<option value="E name">E name</option>
</select>
</form>
</body>
</html>
___________________

Apr 9 '07 #1
2 5199
On Apr 10, 6:23 am, swissrepor...@gmail.com wrote:
Hi - I have a really stupid failure of code, can't figure it out.
Two fields in a form, Textinput and select; if text is written into
input, select changes "selected" to a matching option. This works.
Now I would like to put the WHOLE value of the selected option into
the input field, if the user klicks on something in the select-field.
This DOESN'T work, because I seem not to reference the selected item
correctly.
But then again i did everything according to the various tutorials.
THX for a quick hint.

Code:

___________________
<html>
<head>
<title>Some page</title>
<script language="JavaScript">
The language attribute is depricated, type is required.

<script type="text/javascript">

<!--javascript:
Forget that silliness.

function selectOption(oTxt){
var sel = oTxt.form.select;
var len = sel.options.length;
sel.selectedIndex = len - 1; //select 'Select One' option by default
for (var i=0; i<len; i++){
if (sel.options[i].value.indexOf(oTxt.value)!=-1){
sel.selectedIndex = i;
break;}
Or just return. Indenting of code using 2 spaces is preferred for
posted code, with manual wrapping at about 70 characters.

}
}

//--</script>

<script language="JavaScript">
<!--javascript:
function ChangeField (oTxt){
var stamm = oTxt.form.write;
var sel=oTxt.SelectedIndex;
Javascript is case sensitive, use:

var sel=oTxt.selectedIndex;
--
Fred

Apr 9 '07 #2
THX so much. I KNEW it was something silly...;-)
>
Javascript is case sensitive, use:

var sel=oTxt.selectedIndex;

--
Fred- Hide quoted text -

- Show quoted text -

Apr 9 '07 #3

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

Similar topics

5
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible....
2
by: rked | last post by:
I get nameSPAN1 is undefined when I place cursor in comments box.. <%@ LANGUAGE="VBScript" %> <% DIM ipAddress ipAddress=Request.Servervariables("REMOTE_HOST") %> <html> <head> <meta...
2
by: Alexandre Jaquet | last post by:
Hi, Under IE I could not point why I can't get the selected value from a function here the code function Lvl_P2P(url,closeIt,delay){ //ver1.0 4LevelWebs var fabricant_box; var...
3
by: Nikhil Patel | last post by:
Hi all, I am using the standard System.Windows.Forms.ComboBox controls on a form. There are 5 or 6 comboboxes and their selection depends on each other. The comboboxes behave strangely probably...
3
by: Angel | last post by:
I have a problem I placed a DropDown list control on my .NET page. I do not want to perform a postback when something is selected. When I want to get what was selected in the Client Script I do not...
2
by: ABC | last post by:
How to pre-set combo textbox's selectedindex value from querystring passed from another page? I pass the querystring to set combo text box (change selectedindex on Page_Init). Source code as: ...
4
by: paulbradleysmith | last post by:
Here's a simple script to update the contents of one select based on the user's choice in a second select. It works fine in IE, but not at all in Firefox. Can anyone shed light on the matter? ...
11
by: Faisal Vali | last post by:
Hi - I'm new to javascript and I was reading the book Javascript Professional Projects - there is a fragment that has me a little perplexed, and I was wondering if anyone could explain why and how...
2
by: Adam Benson | last post by:
Hi, If you're not on the UI thread - responding to a network event, say - and you want to read the SelectedIndex of a combo box, do you have to do an Invoke? Or is it just a simple data read...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...

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.