473,396 Members | 1,891 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.

making div appear on dropdown selection


For an ASp Intranet app, I have some code that should work, but I am not able
to make it happen for some reason, after spending considerable time on this.
I am pretty thick when it comes to javascript; I just don't get the syntax
at all. If
anyone could help, I would appreciate it. I'm probably pretty close. Please
note that because it's an Intranet, all users have to use IE 5 or higher.

Situation:
3 form fields on an ASP. <select> box, set of 2 radio buttons, and a text
field.
<Select> box, built by ASP from SQL Server table. One of the 7 choices in
there is the word Closed (Value of 1). When someone selects Closed, I want
a previously hidden div to appear, and it will contain 2 radio buttons (or
a <select> would be fine), with the text of (1)Final Analysis, or (2)Resolution.
Whichever a user selects of these two radio buttons will
populate the text field called BriefDesc with the phrase Final Analysis or
Resolution.

In other words, when a trouble ticket is closed, the boss wants
the tech support people to have the words Final Analysis or Resolution on
the Brief Description field, and this is a way of forcing it to happen, and
keeping it from being mispelled.

Important to note that I cann't hard-code the values of the dropdown. I wish
I could, but I have to make sure that the current value showed up as selected,
so I am using my ASP function below to do that.

Anyway, the page loads fine using the code below; I get no error messages.
But when I click the word Closed, nothing happens.
Here's what I have:

In the head section, I have
<script language="JavaScript">
//this is to make the briefdesc field do great things when the status is
changed to 'closed'
function displayRadios(menu){
if(menu[menu.selectedIndex].text=="Closed"){
document.getElementById(el).style.display="block"
}
}
</script>

Then, in the body of the page, I call an ASP function which builds the list
based on my query. Because this dropdown is showing something that already
has a value in the DB (in other words, one can change the value by using
this dropdown), I have code in there to mark the existing value (which is
in
the variable strStatusNum) as selected. First, the code on the page:

<td><span class="cellnumber">*</span><span
class="celltitle">Status:</span><br>
<select name="StatusID">
<%Set RS = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT StatusID, Description FROM TKT_STATUS "
RS.Open strSQL, objConnection
fillListBox RS,strStatusNum
%>
</select>

<div id ="foo" style="display:none">
<input name="radioclosed" type="radio" value="Resolution"
onclick="BriefDesc.value=this.value" /> Resolution
<input name="radioclosed" type="radio" value="Final Analysis"
onclick="BriefDesc.value=this.value" /> Final Analysis
</div>
</td>
<td><span class="cellnumber">*</span><span class="celltitle">Brief
Description:</span><br>
<input name="BriefDesc" style="WIDTH: 600px; HEIGHT: 22px"
maxlength=100>
</td>

Finally, the code which actually builds the dropdown, and which is located
in an include file:

Private Function fillListBox(recordSet, selected)

'Loop through the recordset and add all the options to the list.
Do Until recordSet.EOF
Response.Write "<option onchange = displayRadios(this) value=""" &
recordSet.Fields(0).Value & """"
'If a list box needs to be selected, check to see if the current value
in
the recordset loop
'is the one that needs to be selected. If so, set it to be selected.
If selected = recordSet.Fields(0).Value Then Response.Write " selected"
Response.Write ">" & recordSet(1).Value & "</option>" & vbCrLf
recordSet.MoveNext
Loop
recordset.Close
End Function

Jul 20 '05 #1
1 2922
middletree wrote:
....
note that because it's an Intranet, all users have to use IE 5 or higher.

Situation:
3 form fields on an ASP. <select> box, set of 2 radio buttons, and a text
field.
<Select> box, built by ASP from SQL Server table. One of the 7 choices in
there is the word Closed (Value of 1). When someone selects Closed, I want
a previously hidden div to appear, and it will contain 2 radio buttons (or
a <select> would be fine), with the text of (1)Final Analysis, or (2)Resolution.
Whichever a user selects of these two radio buttons will
populate the text field called BriefDesc with the phrase Final Analysis or
Resolution.

In other words, when a trouble ticket is closed, the boss wants
the tech support people to have the words Final Analysis or Resolution on
the Brief Description field, and this is a way of forcing it to happen, and
keeping it from being mispelled.

Important to note that I cann't hard-code the values of the dropdown. I wish
I could, but I have to make sure that the current value showed up as selected,
so I am using my ASP function below to do that.
Can the current value be closed?
Anyway, the page loads fine using the code below; I get no error messages.
But when I click the word Closed, nothing happens.
Because there is no event handler assigned to the Select element to do
anything?


Here's what I have:

In the head section, I have
<script language="JavaScript">
//this is to make the briefdesc field do great things when the status is
changed to 'closed'
function displayRadios(menu){
if(menu[menu.selectedIndex].text=="Closed"){
document.getElementById(el).style.display="block" and is el defined? }
}
As an onChange event handler for a select element, I would suggest

function displayRadios( oSel){
var bClosed = oSel.options[oSel.selectedIndex].value == "1";
document.getElementById("foo").style.display =
bClosed ? "block" : none";
}

which allows changes to the closed status by the support agents. If you
don't want to allow them to reopen a case already closed on the DB you
need more code. AIUI the change to look up the "options" collection of
the SELECT element by selectedIndex reflects the standard way of
accessing a selected OPTION element.
</script>

Then, in the body of the page, I call an ASP function which builds the list
based on my query. Because this dropdown is showing something that already
has a value in the DB (in other words, one can change the value by using
this dropdown), I have code in there to mark the existing value (which is
in
the variable strStatusNum) as selected. First, the code on the page: .... <select name="StatusID">
needs to have an event handler, say as
<select name="StatusID" onchange="displayRadios(this)"> <% ' generate some OPTION elements in vbscript... %>
</select>

<div id ="foo" style="display:none">
the display value here may need to be generated in vbscript according to
the current status on the DB - or at least determine what to do if the
case is already closed.
<input name="radioclosed" type="radio" value="Resolution"
onclick="BriefDesc.value=this.value" /> Resolution
<input name="radioclosed" type="radio" value="Final Analysis"
onclick="BriefDesc.value=this.value" /> Final Analysis
</div>
</td>
again, if ops can display an existing closed case a checked attribute
may need to be placed on one of these radio buttons.
<td><span class="cellnumber">*</span><span class="celltitle">Brief
Description:</span><br>
<input name="BriefDesc" style="WIDTH: 600px; HEIGHT: 22px"
maxlength=100> again, this input may need a value attribute generated from current DB
values if a closed case (ticket) can be retrieved. If you prefer no
mispellings, you might like to generate the DB value on the server from
the value of the "radioclosed" radio group returned. </td>

Finally, the code which actually builds the dropdown, and which is located
in an include file:

Private Function fillListBox(recordSet, selected)

'Loop through the recordset and add all the options to the list.
Do Until recordSet.EOF
Response.Write "<option onchange = displayRadios(this) value=""" &
Ohhhh :)
The onchange event belongs on the SELECT element and is not defined for
an OPTION element. Checkout <URL http://www.w3.org/TR/DOM-Level-2-HTML >
for attribute values which *are* defined on OPTION elements.
recordSet.Fields(0).Value & """"
'If a list box needs to be selected, check to see if the current value
in
the recordset loop
'is the one that needs to be selected. If so, set it to be selected.
If selected = recordSet.Fields(0).Value Then Response.Write " selected"
'This doesn't do anything special with already closed cases
Response.Write ">" & recordSet(1).Value & "</option>" & vbCrLf
recordSet.MoveNext
Loop
recordset.Close
End Function


One other comment. The reason I tested equality of the .value attribute
of the OPTION element against "1", and not the .text attribute (value)
against "Closed" is that I have noted problems with IE ignoring setting
the .text value of an OPTION element. It appears to read .text
attributes okay, but I prefer to stay away from known bug areas when
possible.

HTH

cheers,
Dom
Jul 20 '05 #2

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

Similar topics

10
by: JL | last post by:
Does anyone have any ideas on this please? I don't know how to evaluate the no-blank selections against each other from a form as follows: . I have a form with 6 dropdown fields, each...
1
by: Wouter | last post by:
Hi, I would like to make a dropdown menu. When a user select something i want to use his selection in PHP for a next dropdown menu. When the user has selected something in the second dropdown...
4
by: anonymous | last post by:
Hi Folks, I have a form with two Dropdown list boxes, which get loaded with data from Database. DropDownList1 gets data from Table1 and DropDownList2 gets data from Table2 Table1 has a...
0
by: Jeff | last post by:
After I bind the repeater control in the form_load event, it builds multiple lines based on the number of rows in the dataset. In the repeater control, I have a textbox and a dropdown list box. ...
4
by: darrel | last post by:
I and a coworker are building a cms via .net (vb.net) I'm more of the front-end guy, and mainly use DW, while he's more of the back-end guy, and uses VS.NET He likes to use a lot of the built...
2
by: Jason Sobell | last post by:
Hi, I'm trying to figure out a sensible way of making a combobox (configured as a dropdown list) behave in a read-only fashion. Setting Enabled=False will grey the text and the background, but I...
2
by: 23s | last post by:
I have a dropdown bound to a dataview. The binding assigns the dropdown with a SelectedIndex of 0. There is a msgbox in the SelectedIndexChanged event that displays the SelectedIndex property....
3
by: er1 | last post by:
Hi all, I have created a double dropdown list. Based on the first list selection, second list populates (this works fine). I have a submit button, which when clicked should run a select query...
1
by: DeveloperQuest | last post by:
How do I make Xhtml 1.0 strict or Xhtml 1.1 strict appear in the Visual Studio 2005 dropdown? How do I add a Xhtml 1.0 strict to the dropdown in visual studio 2005? I have used the default...
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
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...
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,...

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.