Wednesday, September 16, 2009

jQuery Dynamic value updation

jQuery is one of the powerful Javascript frameworks, I have came across. It has really the potential to change the way a dynamic webpage (interms of UI) is developed. jQuery has a lot of powerful tools built-in viz., XQuery , ever powerful DOM parsing, CSS manipulation, extensibility and another power-packed tool jQuery plugins !

I am writing a following tip which can help you resolve some of your day-to-day jQuery chores. I have discovered this during my wrestling with jQuery.

Scenario: Whenever user types in the Textbox, values here $strNew and $temp1 need to be (sent) updated to the plugin (autocomplete) - "general template", which will be populated and plugin kicks in and populates the autosuggest over the textbox.

If we write
         extraParams : {
          search :  $strNew,
          bizTerm : $temp1
           }
values search and bizTerm will not be updated on every keydown .... if we can update the variable in the below fashion (my code), you achieve your goal of sending dynamic values to the template for generation dynamic autosuggests.


// general Template -snippet


function testTemplate() {

$txtbx.bind('keydown', function(e) {

if($tokenObj.hasValues){
    $tempURL="myClass/myAction.action"
}else{
     $tempURL="/";
}

$strNew=$txtbx9.val();
$temp1=$tokenObj.name

// my code -snippet

$txtbox.autocomplete($tempURL, {
      extraParams : {
          search : function() {
                 return $strNew
           },
          businessTerm : function() {
                return $temp1
           }
 },

(C) Ganesh T

Please feel free to add your comments / suggestions / improvements etc.,

Please check with Manuals. Author is not responsible for any misinformation / incorrect information or typographical errors.

NOTE: If you would like to share any useful info, please contact the authors.

No comments:

Post a Comment

Happy Reading!

Ganex Improves .. Headline Animator