473,830 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple code for selecting matching text in a listbox

got below script, works fine with IE but fails on opera. my js knowledge is
very limited and can't find whats wrong with it.

----------------------------------------------
function selectMatching( x)
{
var S = document.getEle mentById("mymon th");
var L = S.options.lengt h;
for (var i=0; i <= L-1; i++)
{
if ((String(x.valu e).substring(0, 6)) ==
String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
}
}
-------------------------------------

and i use it in below form

-------------------------------------------------
<form method="post" name="myform" action="default .asp">
<p>
Select Month: <select name="mymonth"
onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
<option value="20080401 " selected="selec ted" >April-2008 (25299)</option>
<option value="20080301 " >March-2008 (2)</option>
<option value="20080201 " >February-2008 (1)</option>
</select>
Day: <select name="myday" onChange="selec tMatching(this) ;">
<option value="0" selected="selec ted">All days</option>
<option value="20080401 " >1-Tuesday (1)</option>
<option value="20080420 " >20-Sunday (2)</option>
<option value="20080421 " >21-Monday (1)</option>
<option value="20080425 " >25-Friday (25293)</option>
<option value="20080427 " >27-Sunday (2)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
---------------------------------------------------

what i do is. if user selects from months menu script resets days menu to
all days (doesn't work on opera)

if user changes days menu function finds matching month from the first list
and selects it. Although days has 2 more numbers ad the end by substring i
cut that part.

can anyone offer another solution that would work on opera too without
changing current form and its values?

thanks
Jun 27 '08 #1
2 1535
sdorted with
-----------------------------------
function selectMatching( x)
{
var S = document.myform .elements['mymonth'];
var L = S.options.lengt h;
for (var i=0; i <= L-1; i++)
{
if ((String(x.valu e).substring(0, 6)) ==
String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
}
}

and

function setContent() {
if(document.det ailsform.paymen tMethod.value== "1")
{
document.getEle mentById('payme ntMethodExplain ').innerHTML= "Registered
Paypal e-mail:";
}
if(document.det ailsform.paymen tMethod.value== "2")
{
document.getEle mentById('payme ntMethodExplain ').innerHTML= "Bank account
details:";
}
if(document.det ailsform.paymen tMethod.value== "3")
{
document.getEle mentById('payme ntMethodExplain ').innerHTML= "Full name and
address:";
}
}


".nLL" <no***@here.com wrote in message
news:Kp******** ************@ne wsfe08.ams2...
got below script, works fine with IE but fails on opera. my js knowledge
is very limited and can't find whats wrong with it.

----------------------------------------------
function selectMatching( x)
{
var S = document.getEle mentById("mymon th");
var L = S.options.lengt h;
for (var i=0; i <= L-1; i++)
{
if ((String(x.valu e).substring(0, 6)) ==
String(S.option s[i].value).substri ng(0,6)) {S.selectedInde x=i};
}
}
-------------------------------------

and i use it in below form

-------------------------------------------------
<form method="post" name="myform" action="default .asp">
<p>
Select Month: <select name="mymonth"
onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
<option value="20080401 " selected="selec ted" >April-2008 (25299)</option>
<option value="20080301 " >March-2008 (2)</option>
<option value="20080201 " >February-2008 (1)</option>
</select>
Day: <select name="myday" onChange="selec tMatching(this) ;">
<option value="0" selected="selec ted">All days</option>
<option value="20080401 " >1-Tuesday (1)</option>
<option value="20080420 " >20-Sunday (2)</option>
<option value="20080421 " >21-Monday (1)</option>
<option value="20080425 " >25-Friday (25293)</option>
<option value="20080427 " >27-Sunday (2)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
---------------------------------------------------

what i do is. if user selects from months menu script resets days menu to
all days (doesn't work on opera)

if user changes days menu function finds matching month from the first
list and selects it. Although days has 2 more numbers ad the end by
substring i cut that part.

can anyone offer another solution that would work on opera too without
changing current form and its values?

thanks

Jun 27 '08 #2
..nLL escribió:
got below script, works fine with IE but fails on opera. my js knowledge
is very limited and can't find whats wrong with it.
It doesn't work in Firefox either. So I'd say it only works in IE.

var S = document.getEle mentById("mymon th");
This line finds an HTML tag with id="mymonth". There isn't any on the
page. Replace it with:

var S = document.forms["myform"].mymonth;

This way you call a form element with name "mymonth" in a form with name
"myform":
<form method="post" name="myform" action="default .asp">
<p>
Select Month: <select name="mymonth"
Same here:
onChange="docum ent.getElementB yId('myday').se lectedIndex=0">
onChange="docum ent.forms['myform'].myday.selected Index=0"
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://bits.demogracia.com
-- Mi web de humor al baño María: http://www.demogracia.com
--
Jun 27 '08 #3

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

Similar topics

12
3190
by: Bob Bedford | last post by:
I've a page where users may enter a zip code (text edit) and I want to fill a combobox with existing cities depending on the zip code entered. Let give an example. I've my text edit like: <input name="ZIP" type="text" id="ZIP" onKeyUp="fillcitycombo();"> <select name="City" id="City"></select> When entering the zip code, I'd like the fillcitycombo() function to fill
5
6346
by: Lisa | last post by:
Hello, I am new to using recordsets, and i am completly stuck with this one. I am trying to use a multi select list box to write records to a table. Something in my code is causing the same record to be written over and over, for example if I have 4 items selected, it writes the same item 4 times in my table. Here is my code.
1
1100
by: Lloyd Sheen | last post by:
I am having big time problems seperating the two mention in subject line. I want to create a list of items (listbox or select) from a button click (on the server). The button click will ensure that all data required for viewing the page is within the page and after that selecting items from the table should cause client processing to modify the look of the page. The server code is easy. I access data on the server and add it to the...
5
2736
by: Peter Proost | last post by:
Hi I got this piece of c# code which runs ok but now I translated it to vb.net (see bottom of post for both pieces) and it keeps erroring out at pi.SetValue(testForm, newValue, x) with this error: System.Reflection.TargetParameterCountException: Parameter count mismatch. at System.Reflection.RuntimeMethodInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture, Boolean...
11
1702
by: samuelberthelot | last post by:
Hi, I've got 3 input HTML (dropdown lists) on my page. One for selecting a Month, one for the day, one for the year. Very simple... My problem is that I'd like to update the Days one according to what month was selected (31,30 or 28 days). I should use a simple javascript to populate the input boxes, but I'm a bit new to javascript. Please can you help me ?
3
6636
by: Geoff | last post by:
Two small problems relating to Listboxes in VB6 1) How do I copy an item from the list box when selecting a particular entry 2) How do I set tab stops when adding fields to the list box.
1
2985
by: spamfilteraccount | last post by:
Hi, I want to make a really simple form with C# and windows forms, which is trivial with Java, but I'm unable to reproduce it with .NET. I can't believe it's impossible. I want a simple window with a textbox and a listbox below it. I don't want to use fixed coordinates and sizes, since that's what layout managers are for. I want the textbox and the listbox resize themselves automatically if I resize the window. The textbox should...
4
2112
by: darrel | last post by:
I have a DDL list along these lines: item value="1" text="a" item value="2" text="b" item value="3" text="c" item value="2" text="d" item value="2" text="e" item value="1" text="f" item value="1" text="g"
3
2492
by: deejayquai | last post by:
Hello Simple one this I guess, but I'm quite stuck at the moment. I would like to update the records displayed in my listbox (lstStudents) using criteria selected from my combo (cboForm) in a form. My basic code is:
0
9781
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
10769
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...
1
10522
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
9310
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
7740
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
5615
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...
1
4408
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
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.