Jump to content

Js Populate Specific Textbox During While Loop From Href


Lonig

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 comment
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 comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...