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="JavaS cript">
//this is to make the briefdesc field do great things when the status is
changed to 'closed'
function displayRadios(m enu){
if(menu[menu.selectedIn dex].text=="Closed" ){
document.getEle mentById(el).st yle.display="bl ock"
}
}
</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="cellnumb er">*</span><span
class="celltitl e">Status:</span><br>
<select name="StatusID" >
<%Set RS = Server.CreateOb ject("ADODB.Rec ordset")
strSQL = "SELECT StatusID, Description FROM TKT_STATUS "
RS.Open strSQL, objConnection
fillListBox RS,strStatusNum
%>
</select>
<div id ="foo" style="display: none">
<input name="radioclos ed" type="radio" value="Resoluti on"
onclick="BriefD esc.value=this. value" /> Resolution
<input name="radioclos ed" type="radio" value="Final Analysis"
onclick="BriefD esc.value=this. value" /> Final Analysis
</div>
</td>
<td><span class="cellnumb er">*</span><span class="celltitl e">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(rec ordSet, selected)
'Loop through the recordset and add all the options to the list.
Do Until recordSet.EOF
Response.Write "<option onchange = displayRadios(t his) value=""" &
recordSet.Field s(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.Field s(0).Value Then Response.Write " selected"
Response.Write ">" & recordSet(1).Va lue & "</option>" & vbCrLf
recordSet.MoveN ext
Loop
recordset.Close
End Function
Comment