jQuery when div is clicked update input field issue
Posted
by stogdilla
on Stack Overflow
See other posts from Stack Overflow
or by stogdilla
Published on 2010-05-09T01:15:13Z
Indexed on
2010/05/09
1:18 UTC
Read the original article
Hit count: 252
Hello,
I'm rather new to jquery so this may be the issue. I have a script that outputs several divs all with different text data in them. I would like it when I click one of them that an input field's value is updated to that text currently I have:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("a.results]").click(function() {
data= this.text();
$("#updateme").val(data); });
});
</script>
<p> <label>Field
<input type="text" name="updateme" id="updateme"> </label> </p>
<a href="#" class="results">Florida</a>
<a href="#" class="results">Florida 2</a>
<a href="#" class="results">Florida 3</a>
How can I make it so that whatever link is clicked that is the data that gets updated into the input's value? I can get it to take one or I can script out different cases of each changing the class name but I think there has to be a way where it references whatever link is being clicked instead of what it's currently doing.
Thanks in advance!
© Stack Overflow or respective owner