ginerjm Posted April 14, 2011 Share Posted April 14, 2011 I have a d/e form that has a series of numbered fields - Player1,Player2,Player3... followed by another series - Playername1,Playername2,Playername3... They are related by number naturally. What I want to do is use js to populate the corresponding Playername field when its 'partner' Player field has been modified. So far I've figured that in the html input tag for 'Playern' I would have an 'onchange="gn($i)"' where 'gn($i)' is the function that will pull my name values from a session array i've already built. My question is - how do I post the looked up value to the name field? here is my proposed function header: echo '<script type="text/javascript">'; echo 'function gn(str)'; echo '{'; this is where the lookup to my session array would occur and the posting of the result to my name field. echo '}'; echo '</script>'; here are my current input tags echo '<td><input onchange="gn($i)" type="text" name="Player'.$i.'" tabindex="1'.$i.'" size="4" maxlength="2" value="'.$_POST["Player$i"].'"></td>'; echo '<td><input '.$n_attr.' id="pad" type="text" name="Player'.$i.'" size="25" maxlength="25" value="'.$_POST["Playername$i"].'"></td>'; The input tags are in a for loop controlled by $i. So for any given 'player(n)' field I want to look up in my array for element (n) and then post the array's (n) value to the input tag called 'Playername(n)'. Is this easily doable? Quote Link to comment https://forums.phpfreaks.com/topic/233735-set-a-field-based-on-another-field/ Share on other sites More sharing options...
ginerjm Posted April 14, 2011 Author Share Posted April 14, 2011 Please disregard my post. It dawned on me (once again) that I've made a major mistake in my solution by trying to combine php session vars with js execution. I'll get it down pat one of these days. That said (admitted!) - how would a decent js programmer tackle this problem. d/e form to collect a series of picks from the user. The form should do an immediate display of the associated "names" of the picked items (numbers). There are 12 entries to be made on the form so whatever solution is developed has to be executed 12 times on each form. I had considered doing queries for each change but thought that inefficient, hence my original idea of a session array (which won't work). Can js develop an array (once) to then be used in a js function call that will happen multiple times? Quote Link to comment https://forums.phpfreaks.com/topic/233735-set-a-field-based-on-another-field/#findComment-1201646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.