开发者

jQuery when div is clicked update input field issue

开发者 https://www.devze.com 2022-12-29 10:29 出处:网络
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 inpu

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!


Try getting rid of your bracket: $("a.results]") - should be $("a.results"). That may help.


I think your solution is correct but there are some syntax errors. data= this.text(); should be var data = $(this).text() and $("a.results]") should be $("a.results")

0

精彩评论

暂无评论...
验证码 换一张
取 消