Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am still new to all this so I'm probably not using all the correct terminology. I was wondering if it is possible to link javascript objects to html inputs. For instance, I am using http://arshaw.com/fullcalendar/. When I click on a event in the calendar a callback triggers and I'm passed the event object which contains the title, start, end, etc.

In angular one can link an input to an object by means of

<input type="text" name="title" ng-model="event.title">

So if I click on an event it sets the global object "event" to a different object then the value of the "title" input would change to the title of the event that I clicked on. The same with all the other input fields, so I do not manually have to go and change every input with something like:

<script type="text/javascript>
    function clickEvent(event)
    {
         $.('#title').val(event.title);
         ....
    }
</script>

Is this possible in normal javascript/jQuery, and if so where can I get some proper documentation on this?

share|improve this question

You can use jQuery's .on("input", function(){ ... }) event, to get the value of the input and store it in a object, when the value changes.

obj = {};

$("input[name=title]").on("input", function(){  //jquery on input fires every time the input value is changed
    obj["title"] = $(this).val(); // set the obj's title property to the value of the input
});

Here is a fiddle for it!

share|improve this answer
    
Thank you, but this is not exactly what I was looking for. I would still have to do it to every field, then I might as well just change every field manually like in my original post. I was hoping for a more elegant solution where I can just link every input field to an attribute of an object like <input type="title" name="title" id="title" bind="window.event"> and simply set window.event = { event object returned } when one clicks on an event. – Magnanimity Oct 8 '13 at 16:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.