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!

Fill textbox then make it read only 1

Status
Not open for further replies.

Phudsen

Technical User
Mar 7, 2003
136
A2
Hi,

I have a form with a drop down that has cities. When I select a city, I want the value selected to be sent to the textbox then the textbox becomes readonly. If I change the city again, the value of the textbox changes and it become read only.

The Drop down is called "City"
The Text is called "textfilled"

Here is the code I wrote. After selecting the city the textfield becomes read only, but the problem is that it is not filled with the city I select. Also, is it possible ot make the field background color grey after the drop down is selected:

<script language="javascript">
function FillBox()
{
document.Form1.textfilled.value=document.Form1.City.value
document.Form1.textfilled.readonly="True"
}
</script>

</head>

<body>

<form method="POST" name="Form1" action="--WEBBOT-SELF--">
<!--webbot bot="SaveResults" u-file="_private/form_results.csv" s-format="TEXT/CSV" s-label-fields="TRUE" --><p>
<select size="1" name="City" onChange="JavaScript:FillBox()">
<option selected>Select City</option>
<option>London</option>
<option>Paris</option>
</select></p>
<input type="text" name="textfilled" size=20>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>


Thanks
Paulin
 
Yup... use document.Form.textfilled.disabled=true;

FYI disabled elements don't participate in submit (GET/POST).
 
vongrunt said:
...FYI disabled elements don't participate in submit (GET/POST).

To follow on from that excellent reminder...

The way I got around this (using .disabled) not submitting was to copy the value from the readonly (disabled) input into a hidden input at the same time I put the value into the readonly (disabled) input. Then you pick up the hidden input value server-side on form submission (and don't worry about the disabled one not being submitted).

Jeff
 
Hi,

I put .readonly because I know that diabled does not submit. I want to know how:

1- After selecting value from the drop down the textbox gets populated with the selected value.

2- how to make the background of the textbox grey.

Thanks
 
OK then...
Code:
<script language="javascript">
function FillBox()
{	with( document.Form1 )
	{	if ((iIndex = City.selectedIndex) > 0 )
		{	textfilled.value = City.options[iIndex].text;
			textfilled.readOnly= true;
			textfilled.style.backgroundColor = "#e0e0e0";
		}
		else
		{	textfilled.value = "";
			textfilled.readOnly= false;
			textfilled.style.backgroundColor = "";
		}
	}
}
</script>
 
Hi vongrunt,

Super, this is what I really need.

Simple question.

In the options I have the first one "Select a city" and the rest are cities.

How can I make like that. If I select the option "Select a
city" the textbox becomes blank, white and read only.

To make sure: If the textfield is read only, can I submit it. I know that Disabled can not be submitted.

Thanks a lot
Nice solution


 
This relates to vongrunt's function... Just change the else part of the function to read:

Code:
        {    textfilled.value = "";
            textfilled.readOnly= true;
            textfilled.style.backgroundColor = "#ffffff";
        }

Jeff
 
Thank you vongrunt,
Thank you Jeff,


Just to make sure. If the textbox is readonly, can I submit it to the database?

Thanks



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top