Im work on a form that will dynamicly display objects. The form is completed and working but am adding some features that will appear based on the user selection. I am unable to get the onchange event to work. When I make the selection in the drop down nothing happens. Any help would be great thanks. -
-
<script language="JavaScript">
-
-
function showHideContent( id, show )
-
{
-
var elem = document.getElementById( id );
-
if ( elem )
-
{
-
if ( show )
-
{
-
elem.style.display = 'block';
-
elem.style.visibility = 'visible';
-
}
-
else
-
{
-
elem.style.display = 'none';
-
elem.style.visibility = 'hidden';
-
}
-
}
-
}
-
Once the user selects the choice I want it to check if it matchs. If it does then to make an object visible. -
-
function ModSelection( selection )
-
-
{
-
if ( selection == "Split Case Pick" )
-
{
-
showHideContent( 'SCP1', true);
-
}
-
else
-
showHideContent( 'SCP1', false);
-
}
-
}
-
-
-
</script>
-
-
The selection the user will make there choice. -
-
<div id="Form1">
-
<table width="80%" align="center">
-
<tr>
-
<td width="18%" align="center">
-
<font face="Arial" size="2">
-
-
<label>From Department: </label>
-
-
<% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].value)"" tabindex=""3"">" )
-
-
For a = 0 To UBound( mySQLDepList, 2 )
-
For b = 0 To UBound( mySQLDepList, 1 )
-
Response.Write("<option value='" & mySQLDepList(b, a) & "'>" & mySQLDepList(b, a) & "</option>" & vbCr)
-
Next
-
Next
-
-
Response.Write("</select>" ) %>
-
</font>
-
</td>
-
</tr>
-
</table>
-
</div>
-
-
The choice that will become visible. -
<div style="display:none" id="SCP1">
-
<td><select name="SCPSelection">
-
<option value="M Mod">M Mod</option>
-
<option value="L Mod">L Mod</option>
-
</select></td>
-
</div>
-
-John
8 2414
Hi,
Please check that ,if any of your functions are getting called on onchange event?
Im work on a form that will dynamicly display objects. The form is completed and working but am adding some features that will appear based on the user selection. I am unable to get the onchange event to work. When I make the selection in the drop down nothing happens. Any help would be great thanks. -
-
<script language="JavaScript">
-
-
function showHideContent( id, show )
-
{
-
var elem = document.getElementById( id );
-
if ( elem )
-
{
-
if ( show )
-
{
-
elem.style.display = 'block';
-
elem.style.visibility = 'visible';
-
}
-
else
-
{
-
elem.style.display = 'none';
-
elem.style.visibility = 'hidden';
-
}
-
}
-
}
-
Once the user selects the choice I want it to check if it matchs. If it does then to make an object visible. -
-
function ModSelection( selection )
-
-
{
-
if ( selection == "Split Case Pick" )
-
{
-
showHideContent( 'SCP1', true);
-
}
-
else
-
showHideContent( 'SCP1', false);
-
}
-
}
-
-
-
</script>
-
-
The selection the user will make there choice. -
-
<div id="Form1">
-
<table width="80%" align="center">
-
<tr>
-
<td width="18%" align="center">
-
<font face="Arial" size="2">
-
-
<label>From Department: </label>
-
-
<% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].value)"" tabindex=""3"">" )
-
-
For a = 0 To UBound( mySQLDepList, 2 )
-
For b = 0 To UBound( mySQLDepList, 1 )
-
Response.Write("<option value='" & mySQLDepList(b, a) & "'>" & mySQLDepList(b, a) & "</option>" & vbCr)
-
Next
-
Next
-
-
Response.Write("</select>" ) %>
-
</font>
-
</td>
-
</tr>
-
</table>
-
</div>
-
-
The choice that will become visible. -
<div style="display:none" id="SCP1">
-
<td><select name="SCPSelection">
-
<option value="M Mod">M Mod</option>
-
<option value="L Mod">L Mod</option>
-
</select></td>
-
</div>
-
-John
No theres not. The only onchange event I have is the one I am trying to add.
I was able to get it working but not the way I would like to. I made the change in the ModSelection function but I would like it to compare the text instead of the index number. -
function ModSelection( )
-
-
{
-
if ( document.MainForm.FDepartment1.selectedIndex == 19 )
-
{
-
showHideContent( 'SCP1', true);
-
}
-
else
-
{
-
showHideContent( 'SCP1', false);
-
}
-
}
-
-
</script>
-
Thanks,
-John
Hi,
Please refer this link for how to call onChange event of dropdown box.
I was able to get it working but not the way I would like to. I made the change in the ModSelection function but I would like it to compare the text instead of the index number. -
function ModSelection( )
-
-
{
-
if ( document.MainForm.FDepartment1.selectedIndex == 19 )
-
{
-
showHideContent( 'SCP1', true);
-
}
-
else
-
{
-
showHideContent( 'SCP1', false);
-
}
-
}
-
-
</script>
-
Thanks,
-John
Thanks shweta123 for the help. I was able to figure it out. The link that you referenced was pretty much the same thing I already had except it was using a variable but it still call the index number of the drop down. I needed to compare the text in the drop down not the index value due to the index number would change frequently with the database constently being updated. -
function ModSelection( )
-
{
-
if ( document.MainForm.FDepartment1.options.value == "Split Case Pick" )
-
{
-
showHideContent( 'SCP1', true);
-
}
-
else
-
{
-
showHideContent( 'SCP1', false);
-
}
-
}
-
Plus made one change in the SELECT on the form. -
<% Response.Write( "<select name=""FDepartment1"" onchange=""ModSelection(this.options[this.selectedIndex].text)"" tabindex=""3"">" )
-
Thanks again,
John
I was also wondering if you could have more then one onchange event on the form? Say I have 2 Drop Downs and I would like to have both of them to have an onchange event to fire if a certain selection is made.
Thanks,
John
Hi ,
Please refer the example below if you want to compare the text in the drop down instead of its index. -
-
<html>
-
<head>
-
<script type="text/javascript">
-
function favBrowser()
-
{
-
var mylist=document.getElementById("myList");
-
document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
-
}
-
</script>
-
</head>
-
-
<body>
-
<form>
-
Select your favorite browser:
-
<select id="myList" onchange="favBrowser()">
-
<option>Internet Explorer</option>
-
<option>Netscape</option>
-
<option>Opera</option>
-
</select>
-
<p>Your favorite browser is: <input type="text" id="favorite" size="20"></p>
-
</form>
-
</body>
For your second question , what do you mean by having more than one onChange event ? You can have more than one function which can be called for diffrent dropdown boxes.
I was also wondering if you could have more then one onchange event on the form? Say I have 2 Drop Downs and I would like to have both of them to have an onchange event to fire if a certain selection is made.
Thanks,
John
Thanks for the help shweta123 I was able to get it worked out. As far as my last question disregard it. It was dumb. Anyways thanks again.
-John
Sign in to post your reply or Sign up for a free account.
Similar topics
by: R.G. Vervoort |
last post by:
I am using a javafunction (onclick in select) in which i am calling a
function in php (thats why i send this to both php and javascript
newsgroups).
in the onclick i call the function...
|
by: Covad |
last post by:
Hi all,
For some reason my change() function is only called when the page loads. I'd
much rather it gets called when the select changes.
Here's the code:
window.onload = init;
function...
|
by: dan baker |
last post by:
I am pretty much a newbie with javascript, and would like to get a
little clarification on what I can do with an onChange javascript
event handler.
I have a dynamic page I build with perl and...
|
by: Asit |
last post by:
In JavaScripts checks for an onChange event against the value of the
textbox at the time of the last onChange event. Since an onChange
Event never fired after you changed the text first time ,...
|
by: Zeebra3 |
last post by:
Here goes: I have a web form with several asp:dropdownlists, with
which, when selection is changed I want to fire an event defined in
some clientside js.
The content of the clientside code is...
|
by: jab3 |
last post by:
Hello. I"m new to this group, and to JavaScript in general, so please
forgive me if I breach local etiquette. I'm trying to implement some
client-side 'dynamic' validation on a form. I'm having...
|
by: subhodey |
last post by:
Hello,
I have a ColdFusion online application that has a page having 2 textboxes.
Corresponding to these 2 textboxes I have a Custom tag in coldfusion where the textbox is defined by <input...
|
by: auslandt |
last post by:
I have an HTML file that includes a JavaScript. I would like this JavaScript to be able to create an "onChange=<function>" attribute against the password element.
Here is an example page of the...
|
by: Leena P |
last post by:
i want to basically take some information for the product and let the user
enter the the material required to make this product
1.first page test.php
which takes product code and displays...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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: 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,...
|
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...
| |