Rick Faircloth wrote: > Strange question, I know…and perhaps stranger coding, but… > I’m trying to trigger a function with a text link and it works, but with the > function coded as is, the link has to be clicked twice. > > I’d like to keep the function coded starting with “function > ajaxCreateStoryTitle() {“ > rather than “(document).ready(function() {“ for code organization > purposes, but using > “function… causes the text link to have to be clicked twice to fully > execute the function. > > All this has to do with a method I’m trying to organize a lot of code > that’s needed to > create an ajax-driven, single-interface page. > > Anyway…here’s the trigger link: > <a id=”createStoryTitleLink” class=”link” > onClick=”fnCreateStoryTitle();”>create title</a> > Clicking that link fire this function: > function fnCreateStoryTitle() { ajaxCreateStoryTitle(); } > The function, “ajaxCreateStoryTitle();” starts like this: > ------------------- > function ajaxCreateStoryTitle() { > $(‘#createStoryTitleLink’).click(function() { > titleValue = > $(this).parent().parent().find(‘#createStoryTitleInput)val(); > etc… > ------------------ > Because of this coding, I have to click the text link above twice; once > to trigger the function > > and the second time to trigger the > $(‘#createStoryTitleLink’).click(function() { line. > > I need the “titleValue” line to obtain the value of the text input > “#createStoryTitleInput”. > > Perhaps there’s a different way to get that value other than with the > “click” function? > > There may be a better way to achieve code organization that what I’m > doing, but it’s just > my way of evolving my coding style using jQuery and AJAX. > > Suggestions? Another way to code the function “ajaxCreateStoryTitle()” > and still > be able to reference the titleValue in the input > “#createStoryTitleInput” ??? > > Thanks for taking time to read through this… > > Rick
If you insist to use onClick, then you don't need $(‘#createStoryTitleLink’).click(function() { } it will become like this: function ajaxCreateStoryTitle() { titleValue = $(this).parent().parent().find(‘#createStoryTitleInput)val(); etc… Anyway, personally I'm not like to use onclick. I like the unobtrusive way of jQuery, using either (document).ready(function() { or it short notation: jQuery(function($){ //DOM ready ....code here..... }); The above lines can appear multiple time. I like to write it near the element that need the code, so it keeps the readability and keep the code tidy. -- Donny Kurnia http://hantulab.blogspot.com http://www.plurk.com/user/donnykurnia