Jump to content

set a field based on another field?


ginerjm

Recommended Posts

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?

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.