Preventing onclick from entering value more than once?

  • VeggiesanTaters
  • Newbie
  • Newbie
  • VeggiesanTaters
  • Posts: 7

Post 3+ Months Ago

Hi, Im using this little javascript to enter words into my search form. But whenever someone clicks on it twice, 2 movie titles end up in the search form. How would I make it so only one thing at a time can be inserted into the input form?
Or if someone clicks on 2 different links the first one is deleted and the second one goes in the form. Heres the code I'm using.
Code: [ Select ]
<head>
<script type="text/javascript">
function addText(text){
 document.getElementById('predictad_input_id').value += text;
}
</script>
</head>

<a href="#" onClick="addText('Up (2009)')"><img src="images/new-tab.gif" title="add to search"></a>

<a href="#" onClick="addText('The Tournament (2009)')"><img src="images/new-tab.gif" title="add to search"></a>
  1. <head>
  2. <script type="text/javascript">
  3. function addText(text){
  4.  document.getElementById('predictad_input_id').value += text;
  5. }
  6. </script>
  7. </head>
  8. <a href="#" onClick="addText('Up (2009)')"><img src="images/new-tab.gif" title="add to search"></a>
  9. <a href="#" onClick="addText('The Tournament (2009)')"><img src="images/new-tab.gif" title="add to search"></a>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13502
  • Loc: Florida

Post 3+ Months Ago

The simple answer is replace += with =.

Ideally, you'ld want to change the function name to something like "setText" though so it doesn't get confusing down the road.
  • VeggiesanTaters
  • Newbie
  • Newbie
  • VeggiesanTaters
  • Posts: 7

Post 3+ Months Ago

joebert wrote:
The simple answer is replace += with =.

Ideally, you'ld want to change the function name to something like "setText" though so it doesn't get confusing down the road.

Thanks! :) It works great now.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.