...

View Full Version : Insert drop down value into text field on button click (in loop).



FastCougar
04-22-2004, 04:57 PM
This should explain everything (a picture is worth a thousand words).

http://dev.cavlog.com/misc/images/calc.gif

Page Code:
<!--- Pieces Table --->
<table width="100%" border="0" cellpadding="1" cellspacing="1">
<tr>
<td class="SmallTitle" align="center">&nbsp;</td>
<td class="SmallTitle" align="center">Quantity</td>
<td class="SmallTitle" align="center">Part</td>
<td class="SmallTitle" align="center">Part Selector</td>
</tr>
<cfoutput>
<!--- Part Selector --->
<tr>
<td></td>
<td></td>
<td></td>
<td align="center" valign="top">
<select name="PartSelector">
<cfloop query="qGetParts">
<option value="#partID#">#partID# - #partDesc#</option>
</cfloop>
</select>
</td>
</tr>
<!--- start Pieces/package # (row per line) --->
<cfloop index="i" from="1" to="#form.TotalPiecesHidden#">
<cfparam name="form.Quantity#i#" default="1">
<cfparam name="form.Part#i#" default="">
<cfset QuantityVal = "form.Quantity"&"#i#">
<cfset PartVal = "form.Part"&"#i#">
<tr>
<td align="right" valign="middle" nowrap>
<table border="0" cellpadding="2" cellspacing="0">
<tr>
<td>
<cfif i GT "1">
<cfif i EQ form.TotalPiecesHidden>
<a href="##" style="font-size:9px" onClick="RemovePiece(#i#);"><img src="#CAVVAR_ROOT#/i/ico_delete.gif" alt="Delete Item" border="0" width="18" height="18"></a>
<cfelse>
<img src="#CAVVAR_ROOT#/i/invis.gif" width="18" height="18">
</cfif>
<cfelse>
<img src="#CAVVAR_ROOT#/i/invis.gif" width="18" height="18">
</cfif>
</td>
<td><span class="RequireField">#i#.</span></td>
</tr>
</table>
</td>
<td align="center">
<input type="Text" name="Quantity#i#" value="#evaluate(QuantityVal)#" size="3" maxlength="3" class="DimsInput">
</td>
<td align="center">
<input type="Text" name="Part#i#" value="#evaluate(PartVal)#" size="15" maxlength="25">
</td>
<td align="left">
<input type="button" name="InsertPart#i#" value="<< Insert" onclick="NEED HELP HERE" size="15" maxlength="25">
</td>
</tr>
</cfloop>
</cfoutput>
</table>

Any help you can provide is greatly appreciated!!!

FastCougar
04-22-2004, 05:54 PM
Function:

function InsertPart(field, fieldvalue) {
document.frmCalc['Part'+field].value = fieldvalue;
}

Call:

onclick="InsertPart(#i#, document.frmCalc.PartSelector.value);"

glenngv
04-23-2004, 05:26 AM
Some browsers return nothing or undefined when select.value is used. Use the cross-browser way to get the value of selected item in a select.

onclick="InsertPart(#i#, document.frmCalc.PartSelector.options[document.frmCalc.PartSelector.selectedIndex].value);"

To optimize it a bit, you can reference the form object regardless of its name by using the form property of the button since both the Insert button and the combobox belong to the same form (All form controls have this property that refers to the form they belong to).

onclick="InsertPart(#i#, this.form.PartSelector.options[this.form.PartSelector.selectedIndex].value);"



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum