Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

client side script

Status
Not open for further replies.

lucyc

Programmer
Mar 1, 2002
62
0
0
US
Hi,

I would like to know how can I display a text box when a special value (e.g. "other") is selected from a dropdown box, so users can specify the value in the text box. Thanks.
 
You can create a textbox and set visible = false. Then in the seletedindex changed event of the dropdown, check if they have selected "other", if so, set the textbox visible = TRUE
 
You can hook a javascript event up to the list. It will fire everytime the selection changes. Then in the script check for a certain value. Then you can write an element to a placeholder (like a span or div).

Something like so

Code:
<html>
<head runat="server">
    <title>Report Menu</title>
    <script language ="javascript">
    function ShowReportOptions() {
        var dropDownList = document.getElementById('ddlReports');
        if (dropDownList.selectedIndex != 0) {
            if (dropDownList.options[dropDownList.selectedIndex].value == 'ArrestWorkSheet') {
                {document.getElementById('spnOptions').innerHTML = '<br />Please Enter an Arrest Number<br /><input type="text" id="txtArrestNumber" />';}
            }
        }
        
    }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    
    <select id="ddlReports" runat="server" onchange="ShowReportOptions()">
    <option> </option>
    <option value="ArrestWorkSheet">Arrest Work Sheet</option>
    <option value="ArrestAffidavit">Arrest Affidavit</option>
    </select>
<span id="spnReports" />
</body>
</html>
 
Yes, without postback.

How you do this on ASP.NET??
 
You can't do it with asp.net, you have to use JavaScript. If you set the control's visible state to "false" then it won't get written to the page (until you postback to the server and set it to true), so you need to write it another way...a la javascript.

asp.net = server side
javascript = client side (which is what you want)

The way I mentioned will work in asp.net pages as javascript is "the other half" of asp.net ;-)

Or you could use Atlas, but it isn't officially out yet.
 
jbenson001 and jshurst,

Thanks for your response.

Does anyone know how to do this in javascript?
 
I showed you how in my first post. Although you may have to have a few more things in there so that you can access the values after the text box is displayed (like runat=server)
 
I don't know javascript, can you show me your code?
 
He posted the javascript:
Code:
<html>
<head runat="server">
    <title>Report Menu</title>
    <script language ="javascript">
    [b]function ShowReportOptions() {
        var dropDownList = document.getElementById('ddlReports');
        if (dropDownList.selectedIndex != 0) {
            if (dropDownList.options[dropDownList.selectedIndex].value == 'ArrestWorkSheet') {
                {document.getElementById('spnOptions').innerHTML = '<br />Please Enter an Arrest Number<br /><input type="text" id="txtArrestNumber" />';}
            }
        }
        
    }[/b]
    </script>
</head>
 
This is what I have.....

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Load checkbox list value from table
Me.LoadLookupTable.LoadCheckBoxList(cklistDiagnosedDisableConditions, "Disable_Condition", "usp_Sel_LKP_Disable_Condition")
txtDisableConditionOther.Visible = False
End If
End Sub

on HTML:
<asp:checkboxlist id="cklistDiagnosedDisableConditions" Width="100%" runat="server" RepeatColumns="2"
OnSelectedIndexChanged="ShowReportOptions()"></asp:checkboxlist><asp:label id="Label1" runat="server">(specify other)</asp:label><asp:textbox id="txtDisableConditionOther" Width="616px" runat="server"></asp:textbox>
<script language="javascript">
function ShowReportOptions() {
var dropDownList = document.getElementById('cklistDiagnosedDisableConditions');
if (dropDownList.selectedindex != 0) {
if (dropDownList.options[dropDownList.selectedIndex].value == 'Other') {
{document.getElementById('txtDisableConditionOther').innerHTML = '<br />Please specify<br /><input type="text" id="txtSpecify" />';}
}
}

}
</script>

Once I added these code, my checkbox list is not showing at all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top