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

drop-down and textbox with same name??? 1

Status
Not open for further replies.

jewel464g

Technical User
Jul 18, 2001
198
US
Hi all,

I need to have a drop-down box with realtor names in it and a text box in case the realtor's name isn't in the drop down box. When I tried the following code. The value of realtor is always empty because the text box is empty and seems to reset the value. Is there a way around this? See code below.

<select name=&quot;realtor&quot;>
<option value=&quot;Joan Brown&quot;>Joan Brown</option>
<option value=&quot;Marshall Payne&quot;>Marshall Payne</option>
<option value=&quot;Virginia Jackson&quot;>Virginia Jackson</option>
<option value=&quot;Ann Rawls&quot;>Ann Rawls</option>
<option value=&quot;Melanie Painter&quot;>Melanie Painter</option>
<option value=&quot;Daylon Martin&quot;>Daylon Martin</option>
</select>

&nbsp;&nbsp;OR&nbsp;&nbsp;
<input type=&quot;text&quot; name=&quot;realtor&quot; size=20 maxlength=150>

When faced with a decision, always ask, 'Which would be the most fun?'
 
You cannot have 2 form elements with the same name, otherwise there will be some conflict (as you have experienced).

If you rename one of the two form elements, that will stop the value being blank.

Hope this helps!

Dan
 
I figured as much. I'm storing these values in a database and then using another page to query the database and display the information. Guess I would have to write a bit of code that said if realtor is blank then use realtor2 to display.

Thanks a bunch.

When faced with a decision, always ask, 'Which would be the most fun?'
 
The other option would be to do it all client-side...

The following code will test to see if you've selected a name in the select list or not.

If you have, it will populate the &quot;realtor&quot; field with the value. If you haven't, it will populate the &quot;realtor&quot; field with the value of the textbox:

Code:
<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
	function submitForm()
	{
		var formObj = document.forms['myForm'];
		if (formObj.realtorSelect.selectedIndex == 0)
			formObj.realtor.value = formObj.realtorText.value;
		else
			formObj.realtor.value = formObj.realtorSelect[formObj.realtorSelect.selectedIndex].value;

		formObj.submit();
	}
//-->
</SCRIPT>
</HEAD>
<BODY>

<FORM NAME=&quot;myForm&quot;>
	<input type=&quot;hidden&quot; name=&quot;realtor&quot; value=&quot;&quot;>
	<select name=&quot;realtorSelect&quot;>
		<option value=&quot;&quot; selected>Please select a realtor</option>
		<option value=&quot;Joan Brown&quot;>Joan Brown</option>
		<option value=&quot;Marshall Payne&quot;>Marshall Payne</option>
		<option value=&quot;Virginia Jackson&quot;>Virginia Jackson</option>
		<option value=&quot;Ann Rawls&quot;>Ann Rawls</option>
		<option value=&quot;Melanie Painter&quot;>Melanie Painter</option>
		<option value=&quot;Daylon Martin&quot;>Daylon Martin</option>
	</select>
	<BR><BR>
	Or type in a name if you cannot find one in the list above:<BR>
	<input type=&quot;text&quot; name=&quot;realtorText&quot; size=20 maxlength=150>
	<BR><BR>
	<input type=&quot;button&quot; onClick=&quot;submitForm();&quot; value=&quot;Submit&quot;>
</FORM>

</BODY>
</HTML>

Hope this helps!

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top