Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Other Development Tools
 Disabling form field based on user's action

Author  Topic 

modest
Starting Member

32 Posts

Posted - 2006-10-17 : 18:18:28
Hi,

I have two form fields: One is Dropdown box populated by a table from by database and the other field is 'text input' field called "Others", just like we have Others(States) field while registering at numerous websites.

Here is my question:
I would like to disable the Dropdown box as soon as the User's starts filling in the Other Input box and suppose the user deletes all the characters from Input box, then I would like to enable the Dropdown box.

I can disable/enable the forms by explicit code but my requirement is to do it based on user's action.

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-18 : 14:39:32
You'll need to write some JavaScript in the web page, do you know how to do that? If not post the HTML from the page and someone here will be able to help you add the JavaScript.
Go to Top of Page

modest
Starting Member

32 Posts

Posted - 2006-10-18 : 17:13:22
Thanks for the reply. I don't know how to write the code for that. Here is my existing code with relevant parts:

<td width="130">Select State:</td>
<td width="170">
<select name="m_state">
<option value="."></option>
<!--#include file="getStates.asp"-->
<%
while not selectStates.eof %>
<option value="<%=selectStates.fields("Description")%>"><%=selectStates.fields("Description")%></option>
<% selectStates.movenext
wend %>
</select>
</td>
</tr>
<tr>
<td width="130">OR Specify State:</td>
<td width="170">
<input type="text" name="m_state" size="20" maxlength="20">
</td>
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-18 : 21:34:54
OK, it should be pretty simple, my changes in bold
<td width="130">Select State:</td>
<td width="170">
<select name="m_state" id="StateList">
<option value="."></option>
<!--#include file="getStates.asp"-->
<%
while not selectStates.eof %>
<option value="<%=selectStates.fields("Description")%>"><%=selectStates.fields("Description")%></option>
<% selectStates.movenext
wend %>
</select>
</td>
</tr>
<tr>
<td width="130">OR Specify State:</td>
<td width="170">
<input type="text" name="m_state" size="20" maxlength="20"
onkeyup="document.getElementById('StateList').disabled = (this.value!='');">
</td>
Go to Top of Page

modest
Starting Member

32 Posts

Posted - 2006-10-19 : 17:40:02
Thanks snSQL. It worked very well. You are awesome. However I didn;t undestand why this piece of code still works for the case where the user deletes all the characters from the Specify State inputbox and the Select State box gets enabled again. We never had enabled code in the script then how is it getting enabled automatically without explicitly telling it.

Thanks a lot once again.
Go to Top of Page

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-10-19 : 18:39:30
It is explicitly enabling it

This expression
this.value!=''
evaluates to true when the user has typed something or false when the user clears out the text.

So then the disabled property of the select list is set to true when the user has typed something or false when the user clears out the text. So it is explicity set to true or false as the user types and it is either disabled or not.
Go to Top of Page
   

- Advertisement -