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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank txtbox - allow user key in new values or select frm existing rec

Status
Not open for further replies.

omoo

Programmer
May 30, 2005
87
US
I need a blank textbox which allow user to select a list of existing records in the database. But if the desired value is not in the database, the user can key in the new value in the blank textbox. This value is to be inserted into the database. I can use "select" to list the values and use "input" to create the blank textbox but I have problems putting these 2 together as one single box.

Here is my code:

Code:
<form name="insert_subcon_ratings_records" method="Post" action="insert_subcon_ratings_records.asp" onsubmit="return validate_form2(this)">
<table>
<tr><td width=180><font color=red>*</font>Subcontractor Name: </td>
<td>
<select name="NAME">
	<%
	sql="select DISTINCT NAME from subdb_subcon_rating"
	Set rs = OraDatabase.Execute(sql)
	response.write ("<option value></option>")
	Do While Not rs.EOF
		IF Request("sc_name") = rs("NAME") THEN
 			response.write ("<option value="""&rs("NAME")&""" selected >"&rs("NAME")&"</option>")
		ELSE
 			response.write ("<option value="""&rs("NAME")&""">"&rs("NAME")&"</option>")
		END IF
	rs.MoveNext
	Loop
	%>
</select>
<input type=VARCHAR2 name="NAME" size="50">
</td></tr>
</table><br>
<input type="submit" name="submit_subcon_ratings_records" value="Submit Ratings Records">
<input type="reset" name="reset" value="Reset">
</form>
 
i have an interesting solution that may work well with this, however it's written in javascript. if you're interested, post in the javascript forum, otherwise, these people can help you.

javascript: forum216

*cLFlaVA
----------------------------
[tt]I already made like infinity of those at scout camp...[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
The autocomplete textbox is good but it is not exactly what I wanted. I am not sure if a drop down list together with a textbox which allow user to key in new values is possible.
 
It isn't possible, but you can do something like what your question was asking.

Basically you could create a hard-coded option in your select box that is 'Other'. Set the onChange event in your select list to use javascript to set the associated textbox's disabled attribute to true or false based on whether the 'Other' is selected (or you could set the .style.display to 'none' or 'inline').

In your backend code you would add a pre-step that would check if the 'Other' option had been selected. If that option was selected you would then insert the value from the textbox, re-query if you need an id of that new entry (optional), then assign the value to a variable. If 'Other' hadn't been selected just assign the value from the dropdown to that variable. From here on out process as normal, making sure to usethe value from the variable instead of Request.


Here is an example of the dropdown controlling the textbox:
Code:
<select name="selTest" onChange="document.getElementById('txtOther').style.display=(this.selectedText.toLower() == 'other')?'inline':'none';">
   <%
   ASP Generated values here  
   %>
   <option value=""> Other </option>
</select>
<input type="text" id="txtOther" name="txtOther" style="display: none;">
That should be close to correct, though I wrote it on the fly so it may have a bug (probably selectedText...too many languages recently)

-T

barcode_1.gif
 
Another approach, also using javascript would be to have a textbox populate your dropdown list with new entries with DOM methods.
Provide a textbox and an Add button so if they do not find the entry they want in the selectbox they type it into the textbox then hit Add which calls a function to insert the item into the selectbox. In the function you can set flags to show new items have been added so when you call your database routines you can populate them in, or you can execute an XMLHTTP request immediately to insert the new entry into the database, or whenever you submit the form you just loop through all the entries to see if any do not already exist and need to be added in... Many ways to approach it.



Paranoid? ME?? WHO WANTS TO KNOW????
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top