473,395 Members | 1,863 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,395 software developers and data experts.

dropdown box change index to matching

Hi, i ma trying to change a dropdown box index to mathing value of on
another dropdown box in same form. here is the 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 (26158)</option>
<option value="20080301" >March-2008 (2)</option>
<option value="20080201" >February-2008 (1)</option>
</select>

Day:
<select name="myday" >
<option value="0" >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" selected="selected">25-Friday (26154)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
-------------------------------------------------------------------------------------------------------------------------------------------
when mymonth changes scipt sets myday seleceted index to 0 (ALL days)
and hits submits, data from that month comes but user can first select month
then change day on myday selectbox and hit submit. that would bring wrong
data. so i am trying to prevent that
by changing mymonth data to matching value of myday onchange vent on myday

mymnth value always unique and myday data always incremental (as in
20080401,20080402,20080403)
you would notice myday value has 2 more characters than mymonth data but to
sort this problem out i've got below function

-------------------------------------------------------
function Left(str, n)
{
if (n <= 0) // Invalid bound, return blank string
return "";
else if (n String(str).length) // Invalid bound, return
return str; // entire string
else // Valid bound, return appropriate substring
return String(str).substring(0,n);
}
--------------------------------------------------------------------------------------------------

so, how can i do it?
select name="myday"
onChange="document.getElementById('mymonth').selec tedIndex=?????????????????????????????????">

can anyone give me a clue?

thanks
Jun 27 '08 #1
1 1729
.nLL wrote:
Hi, i ma trying to change a dropdown box index to mathing value of on
another dropdown box in same form. here is the form

--------------------------------------------------------------------
<form method="post" name="myform" action="default.asp">
<p>
Select Month:
<select name="mymonth"
onChange="document.getElementById('myday').selecte dIndex=0">
'myday' is a name-attribute, not an ID.
<option value="20080401" selected="selected" >April-2008 (26158)</option>
Must be:
<option value="20080401" selected>April-2008 (26158)</option>
<option value="20080301" *>March-2008 (2)</option>
<option value="20080201" *>February-2008 (1)</option>
</select>

Day:
<select name="myday" >
<option value="0" >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" selected="selected">25-Friday (26154)</option>
</select>
<input type="submit" value="View"/>
</p>
</form>
--------------------------------------------------------------------
when mymonth changes scipt sets myday seleceted index to *0 (ALL days)
and hits submits, data from that month comes but user can first select month
then change day on myday selectbox and hit submit. that would bring wrong
data. so i am trying to prevent that
by changing mymonth data to matching value of myday onchange vent on myday

mymnth value always unique and myday data always incremental (as in
20080401,20080402,20080403)
[...]

I think you actually don't need any javascript. The selected date is
all the server asks; it could easily strip the month from that if need
be.

<select name="myday">
<option value="20080428">Monday, April 28 2008</option>
<option value="20080509">Friday, May 9 2008</option>
<option value="20080524">Saturday, May 24 2008</option>
<option value="20080608">Sunday, June 8 2008</option>
</select>
<input type="submit">

...does exactly the same and is much more efficient design.

If you want two boxes anyhow, here is a fine example:
http://www.javascripttoolbox.com/lib/dynamicoptionlist/

Hope this helps,

--
Bart
Jun 27 '08 #2

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

Similar topics

1
by: Hermes | last post by:
Hi All, I've tried searching for this answer but have had no joy. Is there anyway with javascript to allow the end user to click in a dropdown box and when they type the first few letters it...
3
by: usenet | last post by:
Hi. If I have an index (or primary key) on 3 columns, will a subset of these columns automatically be indexed also? For example: CREATE INDEX idx ON tbl(cola, colb, colc); Will: SELECT...
4
by: Doslil | last post by:
I have a form which has a subform.In the main form I have only one field (this is a drop down list and has a query attached to it) which selects empno,Name from the EmployeeInformation table. ...
2
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was...
0
by: cindy | last post by:
I have a dynamic datagrid. I have custom classes for the controls public class CreateEditItemTemplateDDL : ITemplate { DataTable dtBind; string strddlName; string strSelectedID; string...
3
by: | last post by:
I have a Datagrid and it has a dropdown. <asp:DropDownList DataSource="<%# PopulateList() %>" OnLoad="SelectIndex" > I assign selected index of the my dropdown in SelectIndex function....
11
by: eureka | last post by:
Hi All, I'm training in Servlets, JSP and JavaScript, I have a web page in which there's a "StudentName" textbox and below it is a "Names" Dropdown list. Initially the Textbox is empty and...
4
by: in da club | last post by:
I have a datagrid and a dropdown in my page. I want to fill dropdown with my pagenumbers. When a user change the dropdown selected index i wnt to display the result on label1. Anytime i change the...
5
by: Kalkin | last post by:
Hi Is it possible to change the data source of a dropdown list in a gridview from another dropdown list selected index changed method in the same gridview? for example I have a dropdown that...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
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...

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.