populate text box

What I need to do is allow user to populate a text box based on link or graphical selection prior to submitting without a page reload.

For example if the user clicked A, then B then C....the value of name would be ABC

<form action="test" method="post">
<input type="text" name="name" value="">
<input type="submit" value="Submit">
</form>
<a href="">A</a>&nbsp;|&nbsp;
<a href="">B</a>&nbsp;|&nbsp;
<a href="">C</a>&nbsp;|&nbsp;
riffraff5Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

surajgupthaCommented:
1) Declare a Global Variable
2) On every Onlick event of Href Append the Href's id/ Name / code to the global
3) Assign that global variable to a hidden variable before submitting the form

Regards,
Hope it Helps
0
VirusMinusCommented:
<html>
<head>
<title>Untitled</title>
<script language="javascript">
<!--
function addText(word) {
  document.myForm.name.value+=word;
}
//-->
</script>
         
</head>

<body>

<form action="test" method="post" name="myForm">
<input type="text" name="name" value="">
<input type="submit" value="Submit">
</form>
<a href="#" onClick="addText('A')">A</a>&nbsp;|&nbsp;
<a href="#" onClick="addText('B')">B</a>&nbsp;|&nbsp;
<a href="#" onClick="addText('C')">C</a>&nbsp;|&nbsp;

  <table width="100%">
<tr>
    <td><a href="javascript:insertTest('text')">text</a><br>
         <a href="javascript:insertTest('more text')">more text</a></td>
</tr>
</table>
</form>
</body>
</html>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
minichickenCommented:
<script language="javascript">
function add_char(char)
{
      form1.textname.value = form1.textname.value + char;
}
</script>

<form name="form1" action="test" method="post">
<input type="text" name="textname" value="">
<input type="submit" value="Submit">
</form>
<a href="#" onClick="add_char('A');">A</a>&nbsp;|&nbsp;
<a href="#" onClick="add_char('B');">B</a>&nbsp;|&nbsp;
<a href="#" onClick="add_char('C');">C</a>&nbsp;|&nbsp;
0
surajgupthaCommented:
If a user clicks a href he actually leaves the page. So there is no simple way it can be done only using javascript.

So i would like to know if the href click would take the user out of the page??
0
VirusMinusCommented:
Glad to be of help, riffraff5.

A hyperlink need not always take you do a different page. A hyperlink can be used to go to the top of the page, a quick jump location etc. the '#' makes it go nowhere.

Cheers
-VM
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.