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

Linked form items

Status
Not open for further replies.

Bramvg

IS-IT--Management
Joined
Jan 16, 2001
Messages
135
Location
BE
Hi,

I've been searching a whole day yesterday to achieve some very simple, I thought, but I don't succeed in doing it.

I have a form with 2 items that need to be linked with each other. But it's not that easy ;-)
First, I have a <select> item where people have to choose their postcal code. When they click on one of the elements I want to show a value (number) in a input type=text field.

eg:

select
<option value=5%> brussels
<option value=7%> antwerp
<option value=5,5%> bruges


When they click on Brussels I want to display the value, 5% in a input type=text field.
I know this must be possible,

but how???? ;-)

Any help more than welcome.

bram

 
You can do this no problem with javascript:

<form name=&quot;frm1&quot;>
<select name=&quot;postcal&quot; onchange=&quot;frm1.showVal.value = frm1.postcal.options[frm1.postcal.selectedIndex].value&quot;>
<option value=5%> brussels
<option value=7%> antwerp
<option value=5,5%> bruges
</select>

<input type=&quot;text&quot; name=&quot;showVal&quot;>

</form>
 
Tnx !

I changed it.
Continuing on the first problem (linked form items), I forgot something. :-)

When you selected an item of the <select> list it will display the value in the input type=text box.

BUT
Once you selected an item of the list, it actually has to contain 2 values. Value 1 is the one that will be displayed in the input type=text box, but the second item (which can be a '1' or a '0') needs to be checked as well.

When it's 1 a text must be displayed (can be printed in a input type=text box as well) saying 'This year', when the value is '0' a text 'Last year' must be displayed.


Sorry: but any help more than welcome
bram
 
Well, this is kind of a kludge, but works. This utilizes the ID of the select list as well -- it is the 1 or 0 that needs passed. Are you populating the select list from outputting a cfquery? If so, then there may be a slightly better way. Otherwise, this should work:

<script language=&quot;JavaScript&quot;>
function showit(x,y) {
var year = &quot;&quot;;
if (parseInt(y) == 1)
year = &quot;This Year&quot;;
else
year = &quot;Last Year&quot;;
frm1.showVal.value = x;
frm1.showYear.value = year;
}

</script>

<form name=&quot;frm1&quot;>
<select name=&quot;postcal&quot; onchange=&quot;javascript:showit(frm1.postcal.options[frm1.postcal.selectedIndex].value,frm1.postcal.options[frm1.postcal.selectedIndex].id);&quot;>
<option id=1 value=5%> brussels
<option id=0 value=7%> antwerp
<option id=1 value=5,5%> bruges
</select>
<br>
<input type=&quot;text&quot; name=&quot;showVal&quot;><br>
<input type=&quot;text&quot; name=&quot;showYear&quot;><br>

</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top