Jump to content

Js Populate Specific Textbox During While Loop From Href

Recommended Posts

This code is supposed to have a link that once clicked auto-populates a textbox with static text of "troublelink".It is on a php page, and used during a "while" loop. Meaning the link is beside several link text boxes and once clicked needs to only populate that text box.

<script language="JavaScript" type="text/javascript">function AutoPop(InputID){ document.getElementsByID(InputID).value = document.getElementsByID(InputID).value + "troublelink";}</script>

(The below is during a PHP while loop, where the $lt is the current Number in the loop. So it will change the goodRefer to "goodRefer1" and so on. I use the name for php usage. I originally used name with this js, but I switched to ID to see what I kept doing wrong.)

<input type=\"text\" id=\"goodRefer" .$lt. "\" name=\"goodRefer" .$lt. "\" />*<a href=\"#div".$lt."\" onClick=\"AutoPop('goodRefer" .$lt. "');\">troublelink</a>

Hope that gives you a general idea. Thanks in advance.

Link to post
Share on other sites

Problem solved. I changed the php and added the javascript into the loop itself. while not the best way, this isn't meant for public use, so it serves it purpose... albeit ugly.

echo "<script language='JavaScript' type='text/javascript'>function AutoPop".$lt."(ItemId){ document.getElementById('goodRefer".$lt."').value = document.getElementById('goodRefer".$lt."').value + ItemId;}</script>";echo "<div class=\"leftinput\">Good Refer:</div> <div class=\"rightinput\"><input type=\"text\" id=\"goodRefer" .$lt. "\" name=\"goodRefer" .$lt. "\" /><a href=\"#\" onClick=\"AutoPop".$lt."('troublelink'); return false;\">*troublelink*</a></div><br />";

The page is far too large and ugly to post the whole thing. So hopefully the above will suffice if anyone else runs into a similar situation.Thanks for the quick response as always Deirdre's Dad. Even if I didn't follow your request this time. You are one of a kind.Edit to add in return false; to the href. Didn't notice I had forgot it until I pumped up the while loop.

Link to post
Share on other sites

Join the conversation

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

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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...