473,396 Members | 2,061 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,396 software developers and data experts.

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.getElementById("mymonth");
var L = S.options.length;
for (var i=0; i <= L-1; i++)
{
if ((String(x.value).substring(0,6)) ==
String(S.options[i].value).substring(0,6)) {S.selectedIndex=i};
}
}
-------------------------------------

and i use it in below form

-------------------------------------------------
<form method="post" name="myform" action="default.asp">
<p>
Select Month: <select name="mymonth"
onChange="document.getElementById('myday').selecte dIndex=0">
<option value="20080401" selected="selected" >April-2008 (25299)</option>
<option value="20080301" >March-2008 (2)</option>
<option value="20080201" >February-2008 (1)</option>
</select>
Day: <select name="myday" onChange="selectMatching(this);">
<option value="0" selected="selected">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 1519
sdorted with
-----------------------------------
function selectMatching(x)
{
var S = document.myform.elements['mymonth'];
var L = S.options.length;
for (var i=0; i <= L-1; i++)
{
if ((String(x.value).substring(0,6)) ==
String(S.options[i].value).substring(0,6)) {S.selectedIndex=i};
}
}

and

function setContent() {
if(document.detailsform.paymentMethod.value=="1")
{
document.getElementById('paymentMethodExplain').in nerHTML= "Registered
Paypal e-mail:";
}
if(document.detailsform.paymentMethod.value=="2")
{
document.getElementById('paymentMethodExplain').in nerHTML= "Bank account
details:";
}
if(document.detailsform.paymentMethod.value=="3")
{
document.getElementById('paymentMethodExplain').in nerHTML= "Full name and
address:";
}
}


".nLL" <no***@here.comwrote in message
news:Kp********************@newsfe08.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.getElementById("mymonth");
var L = S.options.length;
for (var i=0; i <= L-1; i++)
{
if ((String(x.value).substring(0,6)) ==
String(S.options[i].value).substring(0,6)) {S.selectedIndex=i};
}
}
-------------------------------------

and i use it in below form

-------------------------------------------------
<form method="post" name="myform" action="default.asp">
<p>
Select Month: <select name="mymonth"
onChange="document.getElementById('myday').selecte dIndex=0">
<option value="20080401" selected="selected" >April-2008 (25299)</option>
<option value="20080301" >March-2008 (2)</option>
<option value="20080201" >February-2008 (1)</option>
</select>
Day: <select name="myday" onChange="selectMatching(this);">
<option value="0" selected="selected">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.getElementById("mymonth");
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="document.getElementById('myday').selecte dIndex=0">
onChange="document.forms['myform'].myday.selectedIndex=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
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:...
5
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...
1
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...
5
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:...
11
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...
3
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...
1
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...
4
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...
3
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...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
tracyyun
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...
0
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,...
0
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...

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.