Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jan 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Insert drop down value into text field on button click (in loop).

    This should explain everything (a picture is worth a thousand words).



    Page Code:
    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!!!

  • #2
    Regular Coder
    Join Date
    Jan 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Figured it out!!!

    Function:
    Code:
    function InsertPart(field, fieldvalue) {
    	document.frmCalc['Part'+field].value = fieldvalue;
    }
    Call:
    Code:
    onclick="InsertPart(#i#, document.frmCalc.PartSelector.value);"

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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);"
    Last edited by glenngv; 04-23-2004 at 05:37 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •