Link to home
Start Free TrialLog in
Avatar of riffraff5
riffraff5

asked on

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;
Avatar of surajguptha
surajguptha
Flag of United States of America image

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
ASKER CERTIFIED SOLUTION
Avatar of VirusMinus
VirusMinus
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of minichicken
minichicken

<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;
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??
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