By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,403 Members | 880 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,403 IT Pros & Developers. It's quick & easy.

making div appear on dropdown selection

P: n/a

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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.