jQuery when div is clicked update input field issue

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!

-------------Problems Reply------------

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")

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

Category:jquery Views:0 Time:2010-05-09

Related post

  • Jquery some complex data binding to input fields 2011-08-15

    I am trying to add some Jquery functionaliy to my form. Want I want to do: The .greenDiv is standard and should have 100% opacity When either .blackDiv or .redDiv is clicked the .greenDiv should have 50% opacity. And the div that was clicked should h

  • JQuery UI datepicker not showing from input field, but only from around it 2011-11-27

    I have an input field to which I added a datepicker. For some reason, when I click the input field the datepicker won't open, but if I click around it, the datepicker opens and fills in the data in the field. This is the HTML: <div class="row">

  • How to call/bind a jquery datepicker to a label or div instead of an input field 2009-08-11

    I'm working with the jqueryui datepicker on this page - http://jqueryui.com/demos/datepicker/ How do I call it on a label instead of an input field? Is this possible? --------------Solutions------------- I haven't looked at the code but I suspect tha

  • Updating input field dynamically javascript jquery 2011-04-26

    I have my add and remove functions as follows: function AddOtherRefDoc(name, number) { var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>"; var html = "<li><b> Referral Doctor: </b>"+n

  • jQuery checkbox click shows input field - doesn't work 2010-08-24

    I use a jQuery function to show certain hidden text fields once you select something from a select box. This works fine for select boxes but I can't get it to work for a checkbox. Here is the stripped code I tried (in a nutshell) but it's not working

  • Automatically updating input field with math using jquery? 2012-01-17

    Ok I need some help, I have an online calculator where I have to get the lineal meter from two input fields. I need this to be automatic as they input the data. I have no idea how to do this.. any coding help would be greatly appreciated! Here is the

  • jQuery Datepicker and Timepicker for same input field to popup one after another 2009-06-22

    I have a Datepicker and a Timepicker in 2 separate input fields but I need to combine the 2 fields inputs into one for a database call. Wanted to know if I could only use 1 input field for both controls? first call the datepicker and the user would c

  • Is it possible to get the min and max value with jQuery and render it in another input-field? 2010-07-13

    and there we go: I'm writing(in fact it feels more like trying and asking) a GreaseMonkey script using JS and including(also using) the jQuery library. I created another table with some input-fields. Example(input-fields-only): + " < input type=\"

  • jQuery show div on click, hide the others 2010-08-16

    I'd like to have a text area on my page that shows a div and hides the others (let's say 8 other divs). On click, I'd like the chosen div to show and the current div & other divs to hide. Is there a simple solution to this? Possible to build off

  • Jquery display div based on form input 2011-01-11

    Is there a way to use jQuery to display a div based on the input in a formfield. For example if the value typed in the formfield is between 1 and 5 show a div. --------------Solutions------------- var div = $('div').hide(); $('input').keyup(function(

  • Update input field when the value of a select changes? 2011-02-24

    Update inuput field event onchange ? $A = array(A,B,C,D); <select name="A" id="A" onchange="change_val()"> <?php foreach($A as $key=>$val){?> <option value="<?php echo $key?><?php echo $val?"></option> <?php }?

  • Change CSS for parent div when child element (input field) is selected 2011-06-19

    I'm looking to change the class of a parent div when a child input text field is selected or the mouse moves over any of the other elements in the container. I've tried using both jQuery and some of the pseudo classes in CSS to no avail. Javascript:

  • jQuery show div on clicking textarea 2011-07-29

    I have following code: <div class="question"> <span class="text_area> <textarea name="text1" id="response1" rows="3" cols="50"/> </span> <div> <div class="questionRespond"> <input type="checkbox" name="chk_1"/

  • Jquery repeat div on click not clone 2011-09-14

    I need to repeat a div on click under the initial div that is on the page, ie a div with a class exists with a button within it that when clicked repeats the div directly after the div that is already there, this is in a form so needs to be written t

  • jQuery Prevent div's click behavior when inline href is clicked 2011-11-14

    I have a div containing a href. The div has a jQuery live click event: $(".item").live("click", function() { window.location = this.id; }); In the div I have a href: <div class="item" id="/test.html"> <a href="javascript:void(0);" class="tes

  • Hidden div tag vs hidden input field to store client side data in asp.net mvc 3 website? 2011-12-29

    We have a ASP.net MVC 3 website.We had to store many values in hidden fields on client side that are required to be posted later on using AJAX. For some reason i've been using hidden div tags instead of hidden input fields believing it has some perfo

  • JQuery serialize function with an empty input field that has a title attribute 2011-02-10

    I have the following form input field: <input type="text" value="" title="Enter item description" name="description"> When I call JQuery's serialize function on the containing form, it gives me the following: description=Enter+item+description

  • jQuery UI Range Slider values to input field 2011-04-29

    using the jQuery range slider i have been trying to get the values in a hidden input field which will be used for a search. the hidden input field has the same id as the slider fields which the value but the hidden ones done show anything! $(document

  • JQuery simulating keypress event on an input field 2011-05-25

    I have an input field which is dynamically filled with some AJAX, and once it's filled I would like to have JavaScript to automatically press "Enter" (key event 13) on that input inducing another function, which is hidden to me, to trigger. Would it

Copyright (C) dskims.com, All Rights Reserved.

processed in 0.108 (s). 11 q(s)