[jQuery] Re: Passing value from function

2010-02-18 Thread RobG


On Feb 18, 9:15 pm, Charlie22 ch...@post.cz wrote:
 Hi all,
 I have trouble passing value as selector value to other function.

 $(document).ready(function(){
         var id = 'Test';
         $('#Name').keyup(function(){
                 id = '#Mobil';

If you want variables to be local to their enclosing function, declare
them with var.

The variable id has a closure to id in the outer function. Before the
keup runs, id is 'Test'. Afterward, its value is #Mobil.

         });

         $(id).click(function(){

I guess that should be:

   $('#' + id).click(function(){


         console.log(id);

This id also has a closure to the outer id.

         });

 });

 I am getting on console value #Mobil but $(is) is using value
 Test. Thx for help in advance.

All the id variables above refer to the same property of the same
activation object (i.e. they are essentially the same variable).
Modifying any one of them modifies the others.


--
Rob


[jQuery] Re: Passing a string via variable results in NaN

2009-12-22 Thread T.J. Simmons
When you use + like you are there, it's trying to add your string to
something.. which isn't a number, hence NaN.  Could you not do ppost :
{ 'Path' : $FilePath, 'File' : $FileName } ? That would be my
suggestion.

-- T.J.

On Dec 22, 1:58 pm, Adrian Maleska i...@augenpulver-design.de wrote:
 I've got a little problem with passing two strings $FilePath and
 $FileName to the PHP file and I've got no clue why. When I do it this
 way everything's Ok

 ppost : {
                 'Path' : 'temp/',
                 'File' : 'Myfile.jpg'
             },

 Of cause I need to do this via variable but when I do it in this way:

  $FilePath =temp/;
  $FileName =Myfile.jpg;

 ppost : {
                 'Path' : [+$FilePath],
                 'File' : [+$FileName]
             },

 Everything that my PHP code recives is NaN for both variables. Could
 you tell me why and what would be the proper way?

 The entire script:

         function ajaxFileUpload()
         {
                 $(#loading)
                 .ajaxStart(function(){
                         $(this).show();
                 })
                 .ajaxComplete(function(){
                         $(this).hide();
                 });
  $FilePath =temp/;
  $FileName =Myfile.jpg;

                 $.ajaxFileUpload
                 (
                         {
                                 url:'doajaxfileupload.php',
                                 secureuri:false,
                                 fileElementId:'fileToUpload',
                                 ppost : {
                                 'Path' : [+$FilePath],
                                 'File' : [+$FileName]
             },
                                 dataType: 'json',
                                 success: function (data, status)
                                 {

                                 },
                                 error: function (data, status, e)
                                 {
                                         alert(e);
                                 }
                         }
                 )

                 return false;

         }

[jQuery] Re: Passing parameters to a function with a click event

2009-12-15 Thread Scott Sauyet
On Dec 15, 2:34 pm, kenyabob andy.skogr...@gmail.com wrote:
 http://pastebin.com/m6cd05daa

 I am trying to call a function and pass parameters regarding the
 button that called the function. This doesn't seem to do it. What am I
 missing?

First thing I see is that you're not passing a function into .click
().  You're passing the result of calling your function, and since
your function doesn't return anything, you're passing nothing at all.

Second, if you don't want the default behavior of the click
(presumably to submit a form), you need to cancel the event.  You can
use event.preventDefault() or simply return false from your function.

So it would help to convert this:

$(input.Malcolm).click (
checkAnswer($(this).attr('class'), $(this).parent().parent
().attr('id'))
 );

to this:

$(input.Malcolm).click (function(event) {
checkAnswer($(this).attr('class'), $(this).parent().parent
().attr('id'));
return false;
});

Cheers,

  -- Scott


[jQuery] Re: Passing parameters to a function with a click event

2009-12-15 Thread kenyabob
Thanks so much. I am still getting used to some of this stuff, and
you're explanation makes sense, and your solution works as well, so
thanks!

On Dec 15, 12:41 pm, Scott Sauyet scott.sau...@gmail.com wrote:
 On Dec 15, 2:34 pm, kenyabob andy.skogr...@gmail.com wrote:

 http://pastebin.com/m6cd05daa

  I am trying to call a function and pass parameters regarding the
  button that called the function. This doesn't seem to do it. What am I
  missing?

 First thing I see is that you're not passing a function into .click
 ().  You're passing the result of calling your function, and since
 your function doesn't return anything, you're passing nothing at all.

 Second, if you don't want the default behavior of the click
 (presumably to submit a form), you need to cancel the event.  You can
 use event.preventDefault() or simply return false from your function.

 So it would help to convert this:

     $(input.Malcolm).click (
         checkAnswer($(this).attr('class'), $(this).parent().parent
 ().attr('id'))
      );

 to this:

     $(input.Malcolm).click (function(event) {
         checkAnswer($(this).attr('class'), $(this).parent().parent
 ().attr('id'));
         return false;
     });

 Cheers,

   -- Scott


[jQuery] Re: Passing typeof function

2009-11-10 Thread aze
Thanks waseem,

I think I have found what I want

You code also give me some ideas and had used part of it.
Thanks again


[jQuery] Re: Passing typeof function

2009-11-08 Thread aze
Thanks again but it still to hard for me to run the script if i have
several ajax calls, does the obj object (in your code) refreshes when
I do ajax calls and there are button of same type in it?

What I want actually
I have content loaded thru ajax and inside it have buttons and i want
to simplify the button's theme, caption and at the same time passing
function to the click event. I change my code for better understanding

A) in loaded content
a href=# class=btnA/a
a href=# class=btnB/a


then after page load, script will execute as follow

B) in document.ready() of the loaded content
$(.btnA).btnInit(Button A, function () {
alert('This is button A');
   // do some other action_1 when clicked
});
$(.btnB).btnInit(Button B, function () {
alert ('This is button B');
// do some action_2 when clicked
});


different button has different action
then , I have this plugin in a different file

C) included in mainpage
(function($){
$.fn.btnInit = function() {
  function prepare(obj, caption, action) {
obj
.html(caption)
.addClass(fg-button ui-state-default ui-corner-all)
.click(function(){
  // run the function passed by the script in B)
  //
};


return this.each(function(caption, action){
obj = $(this);
prepare(obj, caption, action);
});



};
})(jQuery);

Sorry for this hassle.


[jQuery] Re: Passing typeof function

2009-11-06 Thread aze
ops typo error the plugin is like this

(function($){
$.fn.btnInit = function() {
  function prepare(obj, caption, action) {
obj
.html(caption)
.addClass(fg-button ui-state-default ui-corner-all)
.click(function(){
  // run the action here when click triggered
   alert('Do some action');});
};


return this.each(function(){
obj = $(this);
prepare(obj, caption, action);
});



};
})(jQuery);


[jQuery] Re: Passing typeof function

2009-11-06 Thread aze
Thanks for the reply

but as you can see I need to do initialize something and then hook the
click event. The html markup is like this

a href=# class=btnA/a
a href=# class=btnB/a

then after page load, script will execute as follow

$(.btnA).btnInit(Button A, function () { do some action 1 });
$(.btnB).btnInit(Button B, function () { do some action 2 });


different button has different action
then , I have this plugin

(function($){
$.fn.btnInit = function() {
  function prepare(obj, caption, action) {
obj
.html(caption)
.addClass(fg-button ui-state-default ui-corner-all)
.click(function(){
  // run the action here when click triggered
   alert('Do some action');});
};


return this.each(function(caption, action){
obj = $(this);
prepare(obj, caption, action);
});



};
})(jQuery);


Thanks



Re: [jQuery] Re: Passing typeof function

2009-11-06 Thread waseem sabjee
markup

a href=# class=button buttonaA/a
a href=# class=button buttonbA/a

on page load function

var obj = $(.button);
obj.each(function(i) {
 if(obj.eq(i).hasClass('buttona') {
  obj.eq(i).click(function() {
alert(' I am button A ' );
  });
 }
});


does this work better for you ?

On Fri, Nov 6, 2009 at 11:34 AM, aze az...@oum.edu.my wrote:

 Thanks for the reply

 but as you can see I need to do initialize something and then hook the
 click event. The html markup is like this

 a href=# class=btnA/a
 a href=# class=btnB/a

 then after page load, script will execute as follow

 $(.btnA).btnInit(Button A, function () { do some action 1 });
 $(.btnB).btnInit(Button B, function () { do some action 2 });


 different button has different action
 then , I have this plugin

 (function($){
 $.fn.btnInit = function() {
  function prepare(obj, caption, action) {
obj
.html(caption)
.addClass(fg-button ui-state-default ui-corner-all)
.click(function(){
  // run the action here when click triggered
   alert('Do some action');});
};


return this.each(function(caption, action){
obj = $(this);
prepare(obj, caption, action);
});



 };
 })(jQuery);


 Thanks




Re: [jQuery] Re: Passing typeof function

2009-11-06 Thread waseem sabjee
syntax error

a href=# class=button buttonaA/a
a href=# class=button buttonbA/a

on page load function

var obj = $(.button);
obj.each(function(i) {
 if(obj.eq(i).hasClass('buttona')) {
  obj.eq(i).click(function() {
alert(' I am button A ' );
  });
 }
});

On Fri, Nov 6, 2009 at 11:40 AM, waseem sabjee waseemsab...@gmail.comwrote:

 markup

 a href=# class=button buttonaA/a
 a href=# class=button buttonbA/a

 on page load function

 var obj = $(.button);
 obj.each(function(i) {
  if(obj.eq(i).hasClass('buttona') {
   obj.eq(i).click(function() {
 alert(' I am button A ' );
   });
  }
 });


 does this work better for you ?

 On Fri, Nov 6, 2009 at 11:34 AM, aze az...@oum.edu.my wrote:

 Thanks for the reply

 but as you can see I need to do initialize something and then hook the
 click event. The html markup is like this

 a href=# class=btnA/a
 a href=# class=btnB/a

 then after page load, script will execute as follow

 $(.btnA).btnInit(Button A, function () { do some action 1 });
 $(.btnB).btnInit(Button B, function () { do some action 2 });


 different button has different action
 then , I have this plugin

 (function($){
 $.fn.btnInit = function() {
  function prepare(obj, caption, action) {
obj
.html(caption)
.addClass(fg-button ui-state-default ui-corner-all)
.click(function(){
  // run the action here when click triggered
   alert('Do some action');});
};


return this.each(function(caption, action){
obj = $(this);
prepare(obj, caption, action);
});



 };
 })(jQuery);


 Thanks





[jQuery] Re: passing a variable through an attribute filter

2009-11-03 Thread MorningZ
Craig... just keep one major thought in regards to selectors *
it's just a string *

and whether you hard code it in there or build it up like the post
above demonstrates, in the end you are just passing a string to the
selector engine..


[jQuery] Re: Passing variables to jQuery?

2009-10-08 Thread MorningZ

Give this a try:

jQuery.ajax({
type: 'POST',
url: 'emaildocument.php',
data: { user: test, file: horse.jpg },
cache: false,
complete: function() {
  // unblock when remote call returns
  jQuery.unblockUI();
}
});




On Oct 8, 9:15 am, Simon he...@simonpearce.co.uk wrote:
 Hi,

 I'm using this code:

         jQuery('#sendemail').click(function() {
             // update the block message
             jQuery.blockUI({ message: h1Remote call in progress.../
 h1 });

             jQuery.ajax({
                 type: 'POST',
                 url: 'emaildocument.php',
                                 data: 'user=testfile=horse.jpg',
                 cache: false,
                 complete: function() {
                     // unblock when remote call returns
                     jQuery.unblockUI();
                 }
             });
         });

 But can't understand how I can pass the data variables 'user' and
 'file' from within my PHP page to the jQuery post.

 Any ideas?

 Cheers

 Simon


[jQuery] Re: Passing jQuery object to a function

2009-10-08 Thread James

Try:

setTimeout(function() {
playGlobalNewsFn(tabLink);
return false;
}, timeLag);


On Oct 8, 8:47 am, vmrao maheshpav...@gmail.com wrote:
 I have the following code. I am getting an error in the setTimeout
 function, tabLink is undefined. Not sure what am I doing wrong.

 function playGlobalNewsFn(obj) {
 obj.click();

 }

 $('#playGlobalNews').click(function() {
         var timeLag = 1000;
         $(#tabPanel2 ul li).each(function() {
                 var tabLink = $(this).find(a);
                 setTimeout(playGlobalNewsFn(tabLink); return false;, 
 timeLag);      //
 error here
                 timeLag = timeLag + 3000;
         });

 });




[jQuery] Re: Passing jQuery object to a function

2009-10-08 Thread Michael Geary
And to explain why that makes a difference, when you use a string in
setTimeout it evaluates the code in the global context - as if it were
outside all your functions. So the timeout code can't see the tabLink
variable.

Using a callback function takes care of that, since a nested function can
access the variables of the outer function.

-Mike

On Thu, Oct 8, 2009 at 4:33 PM, James james.gp@gmail.com wrote:


 Try:

 setTimeout(function() {
 playGlobalNewsFn(tabLink);
return false;
 }, timeLag);


 On Oct 8, 8:47 am, vmrao maheshpav...@gmail.com wrote:
  I have the following code. I am getting an error in the setTimeout
  function, tabLink is undefined. Not sure what am I doing wrong.
 
  function playGlobalNewsFn(obj) {
  obj.click();
 
  }
 
  $('#playGlobalNews').click(function() {
  var timeLag = 1000;
  $(#tabPanel2 ul li).each(function() {
  var tabLink = $(this).find(a);
  setTimeout(playGlobalNewsFn(tabLink); return false;,
 timeLag);  //
  error here
  timeLag = timeLag + 3000;
  });
 
  });
 
 



[jQuery] Re: Passing arguments to an ajax call that returns automagically

2009-10-02 Thread Mike Alsup

 I have a bunch of ajax events that are fired one after an other to fill
 different spots on the page. Hence it's important that I know which dom
 element each on of the resulting data is supposed to belong to.

 I was wondering if there is a way I can pass the id of each element into the
 call so that it gets returned automagically without any intervention by the
 server?

 In YUI I can pass any number of arguments to an axax call and these
 areguments are available as part of the response.


You can achieve this sort of thing using closures.  For example:

function getData(id, url) {
$.ajax({
url: url,
success: function(data) {
$(id).html(data);
}
});
}


[jQuery] Re: passing html to browser

2009-09-29 Thread Mike Alsup

 I am currently using the .after to insert html code into the website.
 In the html code I am passing it I have div's with id's and classes.
 I have other jquery functions which look for those id's and classes to
 perform actions when the mouse moves over it, but it does not perform
 the action after it is loaded into the page using the .after.  When I
 view it in firebug I can see the html code there, but when I look at
 the page source the html is not.  I am thinking that the reason the
 jquery functions are not reacting to the inserted html is because it
 really is not there per the view source.  Is this accurate?  Is there
 another way to insert html code and still have jquery recognize it to
 perform other onclick or mouseovers?

When are you binding the mouse events to those element?  Before or
after you inject them into the DOM?  You need to bind them after they
are inserted, or you need to bind them using the live function.

http://docs.jquery.com/Events/live


[jQuery] Re: passing html to browser

2009-09-29 Thread James

In most browsers, directly viewing the source after dynamically adding
content will not have the new content's HTML show up. As you
mentioned, using Firebug you can see the new source, and it works
great.
Additionally, if you have the Firefox's Web Developer Toolbar plug-in,
you can View Generated Source to also obtain that new source (I
haven't tried it in-depth though).

On Sep 28, 4:59 pm, Jasons jwsandb...@gmail.com wrote:
 I am currently using the .after to insert html code into the website.
 In the html code I am passing it I have div's with id's and classes.
 I have other jquery functions which look for those id's and classes to
 perform actions when the mouse moves over it, but it does not perform
 the action after it is loaded into the page using the .after.  When I
 view it in firebug I can see the html code there, but when I look at
 the page source the html is not.  I am thinking that the reason the
 jquery functions are not reacting to the inserted html is because it
 really is not there per the view source.  Is this accurate?  Is there
 another way to insert html code and still have jquery recognize it to
 perform other onclick or mouseovers?


[jQuery] Re: Passing variables to .click

2009-08-26 Thread Richard D. Worth
Another option would be to use the metadata plugin:
http://plugins.jquery.com/project/metadata

- Richard

On Tue, Aug 25, 2009 at 7:59 AM, AMP ampel...@gmail.com wrote:


 Good one,
 Thanks

 On Aug 24, 4:02 pm, James james.gp@gmail.com wrote:
  Since region is not a valid HTML attribute, other ways is to set an
  ID on the element and use that as a reference to data stored elsewhere
  (e.g. a Javascript array or object).
  Depending on whether you have a lot of data or not. Assuming you have
  many onclicks on your page, here's another way to do it.
 
  script
  // JS object
  var myData = {id1:'US', id2:'Europe', id3:'Antarctica'};
 
  $(div.clickme).click(function() {
 var id = this.id;  // 'id1' or 'id2' or 'id3'
 alert(myData.id);  // 'US' or 'Europe' or 'Antarctica'
 // alert(myData[id]);  // same as above});
 
  /script
 
  div id=id1 class=clickmeText 1/div
  div id=id2 class=clickmeText 2/div
  div id=id3 class=clickmeText 3/div
 
  On Aug 23, 2:40 pm, AMP ampel...@gmail.com wrote:
 
 
 
   This is the way I was thinking so could you give me another example
   without attributes (Just so I could learn a different way).
   Thnaks
 
   On Aug 23, 8:05 pm, MorningZ morni...@gmail.com wrote:
 
MANY ways to do this, with this being one of them
 
button id=parsetablebutton region=?php echo $Region ?Some
Text/button
 
then
 
$(#parsetablebutton).click(function() {
var region = $(this).attr(region);  //-- the value from
PHP
 
});
 
again, that's just one way of many
 
On Aug 23, 6:04 pm, AMP ampel...@gmail.com wrote:
 
 Hello,
 I was using this:
 onClick=parsetable('?php echo $Region ?')
 
 but now I want to use the JQuery:
 $(#parsetablebutton).click( function() {
 
 How do I pass the parameter to the function?
 Would I set an attribute and read it with[att=XXX] where the
 attribute
 is the echo'd $Region or is there a better way?
 Thanks- Hide quoted text -
 
- Show quoted text -- Hide quoted text -
 
  - Show quoted text -


[jQuery] Re: Passing variables to .click

2009-08-25 Thread AMP

Good one,
Thanks

On Aug 24, 4:02 pm, James james.gp@gmail.com wrote:
 Since region is not a valid HTML attribute, other ways is to set an
 ID on the element and use that as a reference to data stored elsewhere
 (e.g. a Javascript array or object).
 Depending on whether you have a lot of data or not. Assuming you have
 many onclicks on your page, here's another way to do it.

 script
 // JS object
 var myData = {id1:'US', id2:'Europe', id3:'Antarctica'};

 $(div.clickme).click(function() {
    var id = this.id;  // 'id1' or 'id2' or 'id3'
    alert(myData.id);  // 'US' or 'Europe' or 'Antarctica'
    // alert(myData[id]);  // same as above});

 /script

 div id=id1 class=clickmeText 1/div
 div id=id2 class=clickmeText 2/div
 div id=id3 class=clickmeText 3/div

 On Aug 23, 2:40 pm, AMP ampel...@gmail.com wrote:



  This is the way I was thinking so could you give me another example
  without attributes (Just so I could learn a different way).
  Thnaks

  On Aug 23, 8:05 pm, MorningZ morni...@gmail.com wrote:

   MANY ways to do this, with this being one of them

   button id=parsetablebutton region=?php echo $Region ?Some
   Text/button

   then

   $(#parsetablebutton).click(function() {
           var region = $(this).attr(region);  //-- the value from
   PHP

   });

   again, that's just one way of many

   On Aug 23, 6:04 pm, AMP ampel...@gmail.com wrote:

Hello,
I was using this:
onClick=parsetable('?php echo $Region ?')

but now I want to use the JQuery:
$(#parsetablebutton).click( function() {

How do I pass the parameter to the function?
Would I set an attribute and read it with[att=XXX] where the attribute
is the echo'd $Region or is there a better way?
Thanks- Hide quoted text -

   - Show quoted text -- Hide quoted text -

 - Show quoted text -


[jQuery] Re: Passing variables to .click

2009-08-24 Thread James

Since region is not a valid HTML attribute, other ways is to set an
ID on the element and use that as a reference to data stored elsewhere
(e.g. a Javascript array or object).
Depending on whether you have a lot of data or not. Assuming you have
many onclicks on your page, here's another way to do it.

script
// JS object
var myData = {id1:'US', id2:'Europe', id3:'Antarctica'};

$(div.clickme).click(function() {
   var id = this.id;  // 'id1' or 'id2' or 'id3'
   alert(myData.id);  // 'US' or 'Europe' or 'Antarctica'
   // alert(myData[id]);  // same as above
});
/script

div id=id1 class=clickmeText 1/div
div id=id2 class=clickmeText 2/div
div id=id3 class=clickmeText 3/div


On Aug 23, 2:40 pm, AMP ampel...@gmail.com wrote:
 This is the way I was thinking so could you give me another example
 without attributes (Just so I could learn a different way).
 Thnaks

 On Aug 23, 8:05 pm, MorningZ morni...@gmail.com wrote:

  MANY ways to do this, with this being one of them

  button id=parsetablebutton region=?php echo $Region ?Some
  Text/button

  then

  $(#parsetablebutton).click(function() {
          var region = $(this).attr(region);  //-- the value from
  PHP

  });

  again, that's just one way of many

  On Aug 23, 6:04 pm, AMP ampel...@gmail.com wrote:

   Hello,
   I was using this:
   onClick=parsetable('?php echo $Region ?')

   but now I want to use the JQuery:
   $(#parsetablebutton).click( function() {

   How do I pass the parameter to the function?
   Would I set an attribute and read it with[att=XXX] where the attribute
   is the echo'd $Region or is there a better way?
   Thanks- Hide quoted text -

  - Show quoted text -




[jQuery] Re: Passing variables to .click

2009-08-23 Thread MorningZ

MANY ways to do this, with this being one of them

button id=parsetablebutton region=?php echo $Region ?Some
Text/button

then

$(#parsetablebutton).click(function() {
var region = $(this).attr(region);  //-- the value from
PHP

});


again, that's just one way of many



On Aug 23, 6:04 pm, AMP ampel...@gmail.com wrote:
 Hello,
 I was using this:
 onClick=parsetable('?php echo $Region ?')

 but now I want to use the JQuery:
 $(#parsetablebutton).click( function() {

 How do I pass the parameter to the function?
 Would I set an attribute and read it with[att=XXX] where the attribute
 is the echo'd $Region or is there a better way?
 Thanks


[jQuery] Re: Passing variables to .click

2009-08-23 Thread AMP

This is the way I was thinking so could you give me another example
without attributes (Just so I could learn a different way).
Thnaks

On Aug 23, 8:05 pm, MorningZ morni...@gmail.com wrote:
 MANY ways to do this, with this being one of them

 button id=parsetablebutton region=?php echo $Region ?Some
 Text/button

 then

 $(#parsetablebutton).click(function() {
         var region = $(this).attr(region);  //-- the value from
 PHP

 });

 again, that's just one way of many

 On Aug 23, 6:04 pm, AMP ampel...@gmail.com wrote:



  Hello,
  I was using this:
  onClick=parsetable('?php echo $Region ?')

  but now I want to use the JQuery:
  $(#parsetablebutton).click( function() {

  How do I pass the parameter to the function?
  Would I set an attribute and read it with[att=XXX] where the attribute
  is the echo'd $Region or is there a better way?
  Thanks- Hide quoted text -

 - Show quoted text -


[jQuery] Re: Passing a jquery object as a function parameter

2009-06-28 Thread Richard D. Worth
Passing a jQuery object as a function parameter is no problem. It looks like
you've got a bug in your selector. Change

  doStuff($('myForm'));

to

  doStuff($('#myForm'));

Even though you said your later code works, seems you have the same issue
there as well, as you're doing

  function doStuff(theform) {
 $(theform).show();
  }
  doStuff('myForm');

instead of

  function doStuff(theformId) {
 $('#' + theformId).show();
  }
  doStuff('myForm');

or

  function doStuff(theform) {
 $(theform).show();
  }
  doStuff('#myForm');

- Richard

On Sun, Jun 28, 2009 at 12:47 AM, ferdjuan afr...@gmail.com wrote:


 I had a script that was acting unexpectedly because of a function
 parameter. I was trying to pass a jquery object through a function to
 attach some events. I was wondering if someone could tell me why this
 didn't fly:

 function doStuff(theform) {
theform.show();
 }

 doStuff($('myForm'));

 The fix was to pass the id as a string:

 function doStuff(theform) {
$(theform).show();
 }

 doStuff('myForm');

 Is there a reason why I couldn't pass the object directly through?
 Thanks

 Thanks


[jQuery] Re: Passing a jquery object as a function parameter

2009-06-28 Thread Ricardo

I'd advise you to use the second one, since it allows you to pass
either selector strings, jQuery objects or DOM elements, a lot more
flexible.

On Jun 28, 1:47 am, ferdjuan afr...@gmail.com wrote:
 I had a script that was acting unexpectedly because of a function
 parameter. I was trying to pass a jquery object through a function to
 attach some events. I was wondering if someone could tell me why this
 didn't fly:

 function doStuff(theform) {
     theform.show();

 }

 doStuff($('myForm'));

 The fix was to pass the id as a string:

 function doStuff(theform) {
     $(theform).show();

 }

 doStuff('myForm');

 Is there a reason why I couldn't pass the object directly through?
 Thanks

 Thanks


[jQuery] Re: Passing a jquery object as a function parameter

2009-06-28 Thread MorningZ

yeah, Ricardo has it right, as something like

form id=myForm
...
/form

then the function

function doStuff(theform) {
$(theform).show();
}

would work with any three of these calls:

doStuff(#myForm);   //call with selector string
doStuff($(#myForm))   //call with jQuery object
doStuff(document.getElementById(myForm)   //call by DOM element



On Jun 28, 3:29 pm, Ricardo ricardob...@gmail.com wrote:
 I'd advise you to use the second one, since it allows you to pass
 either selector strings, jQuery objects or DOM elements, a lot more
 flexible.

 On Jun 28, 1:47 am, ferdjuan afr...@gmail.com wrote:

  I had a script that was acting unexpectedly because of a function
  parameter. I was trying to pass a jquery object through a function to
  attach some events. I was wondering if someone could tell me why this
  didn't fly:

  function doStuff(theform) {
      theform.show();

  }

  doStuff($('myForm'));

  The fix was to pass the id as a string:

  function doStuff(theform) {
      $(theform).show();

  }

  doStuff('myForm');

  Is there a reason why I couldn't pass the object directly through?
  Thanks

  Thanks


[jQuery] Re: Passing a PHP variable to jQuery

2009-06-01 Thread GravyFace

On Mon, Jun 1, 2009 at 3:37 PM, Mike C snib...@gmail.com wrote:

 So I'm going to be printing a list of items from a database, and with
 each item there will be a link printed with it. Essentially, I want
 something like a href=link from database id=link_1Load/a,
 except I want the link to use ajax. So in my scripts.js file I'll have
 something like $('#link_1').click( function() { $('#link_1').load
 (link from database)}); I want to get the link from database from
 the PHP file that contains the initial link. How would I do this?


You need to read up on jquery AJAX (getting the data from .php) and
JSON (the data format that your database links should be in).


[jQuery] Re: Passing a PHP variable to jQuery

2009-06-01 Thread Isaac Gonzalez


I personally would just use jQuery's .get() method. Then with your PHP  
pages you can use xml, json, or html snippets. I tend to use html  
snippets.


i.e.

HTML
a href=MyNewBadAssDynamicPage.php?id=1 id=BadAssPage1View Bad  
Ass Page/a

div id=BadAssPageContent/div


JAVASCRIPT -
$('#BadAssPage1').click(function(){
var pagelink = $('#BadAssPage1').attr('href');
$.get(pagelink, function(data){
 $('#BadAssPageContent').html(data);
 });
});


PHP - MyNewBadAssDynamicPage.php

?php
$id = $_GET['id']
// load db stuff form $id
?
div class=coolstuff?php echo $dbStuff; ?/div


When I was first learning jQuery one thing help me get use to the idea  
of ajax is not to think of databases or dynamic data. jQuery really  
could careless if it's loading a php, asp, js, or even html page. All  
it needs is a valid link to load the data. Once the data is loaded it  
then needs a function to decide what to do with the data. That's it.


Coming from a PHP  Actionscript background I would say the hardest  
part of learning jQuery was excepting it's simplicity.




On Jun 1, 2009, at 12:37 PM, Mike C wrote:



So I'm going to be printing a list of items from a database, and with
each item there will be a link printed with it. Essentially, I want
something like a href=link from database id=link_1Load/a,
except I want the link to use ajax. So in my scripts.js file I'll have
something like $('#link_1').click( function() { $('#link_1').load
(link from database)}); I want to get the link from database from
the PHP file that contains the initial link. How would I do this?




[jQuery] Re: Passing a PHP variable to jQuery

2009-06-01 Thread Mike C

Thanks for the replies! :D

On Jun 1, 1:12 pm, Isaac Gonzalez ier...@gmail.com wrote:
 I personally would just use jQuery's .get() method. Then with your PHP  
 pages you can use xml, json, or html snippets. I tend to use html  
 snippets.

 i.e.

 HTML
 a href=MyNewBadAssDynamicPage.php?id=1 id=BadAssPage1View Bad  
 Ass Page/a
 div id=BadAssPageContent/div

 JAVASCRIPT -
 $('#BadAssPage1').click(function(){
         var pagelink = $('#BadAssPage1').attr('href');
         $.get(pagelink, function(data){
          $('#BadAssPageContent').html(data);
       });

 });

 PHP - MyNewBadAssDynamicPage.php

 ?php
 $id = $_GET['id']
 // load db stuff form $id
 ?
 div class=coolstuff?php echo $dbStuff; ?/div

 When I was first learning jQuery one thing help me get use to the idea  
 of ajax is not to think of databases or dynamic data. jQuery really  
 could careless if it's loading a php, asp, js, or even html page. All  
 it needs is a valid link to load the data. Once the data is loaded it  
 then needs a function to decide what to do with the data. That's it.

 Coming from a PHP  Actionscript background I would say the hardest  
 part of learning jQuery was excepting it's simplicity.

 On Jun 1, 2009, at 12:37 PM, Mike C wrote:



  So I'm going to be printing a list of items from a database, and with
  each item there will be a link printed with it. Essentially, I want
  something like a href=link from database id=link_1Load/a,
  except I want the link to use ajax. So in my scripts.js file I'll have
  something like $('#link_1').click( function() { $('#link_1').load
  (link from database)}); I want to get the link from database from
  the PHP file that contains the initial link. How would I do this?


[jQuery] Re: passing elem id to a JS function...

2009-04-20 Thread kali

thank you very much!!

(why can't I see my posts here? 
http://groups.google.com/group/jquery-en/topics?gvc=2
(I can only see my posts if I search for my uid (kali)

ok, thank you very much.. sorry for two test-posts I have posted..



On Apr 15, 2:47 pm, mkmanning michaell...@gmail.com wrote:
  var img_top  = $(#+curr_img);

 On Apr 15, 8:57 am,kalimaya778...@yahoo.com wrote:

  hi, am trying to do image-hide/img-show with jQuery (now use 'regular'
  JavaScript DOM-scripting..  want to switch to jQuery..  but am having
  some difficulties:

  I have this function-call in interface:

    get_img('photo1','nav1','navAll1','photo2','nav2','navAll2')

  in function -- old way:

  function get_img
  (curr_img,curr_nav,curr_navAll,new_img,new_nav,new_navAll)  {
          var img_top    = document.getElementById(curr_img);
          var img_new    = document.getElementById(new_img);    //  etc..

  how do I do this in jQuery?  I tried:

          var img_top    = $(#curr_img);
          var img_top    = $(curr_img);

  neither one of these is working..  and worst problem is I don't get
  errors in Firefox Error Console (jQuery syntax errors don't show in FF
  Error Console...  is there a place where you can check your jQuery
  syntax??)

  the element id's are passed to the function as string values..  so how
  do I add this string value to a wrapper like this

      $('# id passed to function')

  thank you...

  thank you very much...


[jQuery] Re: passing more than 1 param via click()?

2009-04-19 Thread kgosser

Bump. I'm really looking for a solid tip here :). Thanks everyone.

On Apr 17, 9:48 am, kgosser kgos...@gmail.com wrote:
 Here's a better example with HTML. See, I said it was hard to explain
 in the first place :).

 Ok, so basically think of this as a list of things where the HTML is
 always going to be the same, but there could be between 1 and N rows.
 I'm trying to remove the onClick, and target just the link's class so
 that when a specific link is licked, that specific row is removed.

 Here's some example HTML iterated:

 div id=123
         h1Example A/h1
         a href=#remove  class=remove-link onclick=removeDept
 ('123','listA');return false;Remove/a
 /div
 div id=456
         h1Example B/h1
         a href=#remove class=remove-link onclick=remove
 ('456','listB');return false;Remove/a
 /div

 I want to take out the onClick. So here's what I got in the
 JavaScript:

 $(document).ready(function(){
         // consider the example 123 as the dynamic ROW_ID
         // consider the example listA as the dynamic  LIST_ID
         $(.remove-link).click(function(){
                 exampleAjaxFunction(ROW_ID,LIST_ID,function(){
                         // call back if deleted from DB
                         $(this).parent().remove();
                 });
                 return false;
         });

 });

 And so my question is. I don't know how to pass ROW_ID and LIST_ID
 to the single function like the onClick could.. Normally with just one
 param to pass, I could grab it by targeting an a's rel attribute.
 But now there are TWO, and that's my point...There has to be a better
 way to get those than just getting attributes, and that's what I'm
 trying to figure out.

 Thanks for the help again everyone.

 On Apr 17, 12:15 am, Michael Geary m...@mg.to wrote:

  I must be missing something obvious, but it sounds like you're not just
  working with some predetermined HTML, but you have the flexibility to tweak
  that HTML code, is that right?

  Then why can't you generate this as part of your HTML page:

      script type=text/javascript
          // initialize some variables here
      /script

  That *is* HTML code, isn't it?

  -Mike

   From: kgosser

   I have two values that are only found in a loop in the HTML.
   They need to be passed to the single function in the document.ready().

   I can't set them in the JavaScript. I have to find them
   somehow in the HTML. Whether I find them as hidden inputs or
   something, or as tags to the anchor, or as params passed in
   somehow. I'm not sure what's best.


[jQuery] Re: passing more than 1 param via click()?

2009-04-17 Thread kgosser

Here's a better example with HTML. See, I said it was hard to explain
in the first place :).

Ok, so basically think of this as a list of things where the HTML is
always going to be the same, but there could be between 1 and N rows.
I'm trying to remove the onClick, and target just the link's class so
that when a specific link is licked, that specific row is removed.

Here's some example HTML iterated:

div id=123
h1Example A/h1
a href=#remove  class=remove-link onclick=removeDept
('123','listA');return false;Remove/a
/div
div id=456
h1Example B/h1
a href=#remove class=remove-link onclick=remove
('456','listB');return false;Remove/a
/div

I want to take out the onClick. So here's what I got in the
JavaScript:

$(document).ready(function(){
// consider the example 123 as the dynamic ROW_ID
// consider the example listA as the dynamic  LIST_ID
$(.remove-link).click(function(){
exampleAjaxFunction(ROW_ID,LIST_ID,function(){
// call back if deleted from DB
$(this).parent().remove();
});
return false;
});
});

And so my question is. I don't know how to pass ROW_ID and LIST_ID
to the single function like the onClick could.. Normally with just one
param to pass, I could grab it by targeting an a's rel attribute.
But now there are TWO, and that's my point...There has to be a better
way to get those than just getting attributes, and that's what I'm
trying to figure out.

Thanks for the help again everyone.

On Apr 17, 12:15 am, Michael Geary m...@mg.to wrote:
 I must be missing something obvious, but it sounds like you're not just
 working with some predetermined HTML, but you have the flexibility to tweak
 that HTML code, is that right?

 Then why can't you generate this as part of your HTML page:

     script type=text/javascript
         // initialize some variables here
     /script

 That *is* HTML code, isn't it?

 -Mike

  From: kgosser

  I have two values that are only found in a loop in the HTML.
  They need to be passed to the single function in the document.ready().

  I can't set them in the JavaScript. I have to find them
  somehow in the HTML. Whether I find them as hidden inputs or
  something, or as tags to the anchor, or as params passed in
  somehow. I'm not sure what's best.


[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread Joseph Le Brech

i think itll be covered in this.

http://stackoverflow.com/questions/224820/how-do-you-pass-arguments-to-anonymous-functions-in-javascript

 Date: Thu, 16 Apr 2009 14:46:41 -0700
 Subject: [jQuery] passing more than 1 param via click()?
 From: kgos...@gmail.com
 To: jquery-en@googlegroups.com
 
 
 Hey all,
 
 Not really sure how to ask this, so I'm sorry if my title is mis-
 leading. It is also why I wasn't able to find much searching, so I'm
 sorry if it's answered already.
 
 Basically, the code I inherited was this:
 
 a
  href=#drop
  class=edit-link
  onclick=
   removeDept('c:out value=${key} /','c:out value=$
 {name} /');
   return false;
 Remove Department/a
 
 And that is in an iteration, so the two values passed to the
 removeDept function are always dynamic.
 
 I'm trying to handle this in the document.ready(). Normally, I throw
 the would-be dynamic param passed as a rel tag on an anchor, and
 that's how I retrieve things when I clean up code like this.
 
 However, I'm scratching my head for the *best* way to handle this with
 the two params now... How do you guys recommend I handle something
 like that?
 
 $(document).ready(function() {
   $(.edit-link).click(function(){
removeDept($(this).attr(rel),$(this).attr(rel));
return false;
   });
 });
 
 
 
 Obviously I can't have two rel attributes :)
 
 
 Thanks in advance.

_
View your Twitter and Flickr updates from one place – Learn more!
http://clk.atdmt.com/UKM/go/137984870/direct/01/

[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread Josh Nathanson

You could do something like:

a rel=val1_val2 // use a delimiter that makes sense for your values

Then split the rel:

var arr = this.rel.split('_'), val1 = arr[0], val2 = arr[1];

removeDept( val1, val2 );

-- Josh

-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
Behalf Of kgosser
Sent: Thursday, April 16, 2009 2:47 PM
To: jQuery (English)
Subject: [jQuery] passing more than 1 param via click()?


Hey all,

Not really sure how to ask this, so I'm sorry if my title is mis-
leading. It is also why I wasn't able to find much searching, so I'm
sorry if it's answered already.

Basically, the code I inherited was this:

a
 href=#drop
 class=edit-link
 onclick=
  removeDept('c:out value=${key} /','c:out value=$
{name} /');
  return false;
Remove Department/a

And that is in an iteration, so the two values passed to the
removeDept function are always dynamic.

I'm trying to handle this in the document.ready(). Normally, I throw
the would-be dynamic param passed as a rel tag on an anchor, and
that's how I retrieve things when I clean up code like this.

However, I'm scratching my head for the *best* way to handle this with
the two params now... How do you guys recommend I handle something
like that?

$(document).ready(function() {
$(.edit-link).click(function(){
   removeDept($(this).attr(rel),$(this).attr(rel));
   return false;
});
});



Obviously I can't have two rel attributes :)


Thanks in advance.



[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread kgosser

I think you've misunderstood my question.

I have two values that are only found in a loop in the HTML. They need
to be passed to the single function in the document.ready().

I can't set them in the JavaScript. I have to find them somehow in
the HTML. Whether I find them as hidden inputs or something, or as
tags to the anchor, or as params passed in somehow. I'm not sure
what's best.

Basically, there could be 10 edit-link classes, but when a specific
edit-link anchor is clicked, I need to perform an Ajax function that
needs two params passed into it that are unique to that edit-link.

On Apr 16, 4:53 pm, Joseph Le Brech jlebr...@hotmail.com wrote:
 i think itll be covered in this.

 http://stackoverflow.com/questions/224820/how-do-you-pass-arguments-t...



  Date: Thu, 16 Apr 2009 14:46:41 -0700
  Subject: [jQuery] passing more than 1 param via click()?
  From: kgos...@gmail.com
  To: jquery-en@googlegroups.com

  Hey all,

  Not really sure how to ask this, so I'm sorry if my title is mis-
  leading. It is also why I wasn't able to find much searching, so I'm
  sorry if it's answered already.

  Basically, the code I inherited was this:

  a
       href=#drop
       class=edit-link
       onclick=
            removeDept('c:out value=${key} /','c:out value=$
  {name} /');
            return false;
  Remove Department/a

  And that is in an iteration, so the two values passed to the
  removeDept function are always dynamic.

  I'm trying to handle this in the document.ready(). Normally, I throw
  the would-be dynamic param passed as a rel tag on an anchor, and
  that's how I retrieve things when I clean up code like this.

  However, I'm scratching my head for the *best* way to handle this with
  the two params now... How do you guys recommend I handle something
  like that?

  $(document).ready(function() {
     $(.edit-link).click(function(){
                 removeDept($(this).attr(rel),$(this).attr(rel));
                 return false;
     });
  });

  Obviously I can't have two rel attributes :)

  Thanks in advance.

 _
 View your Twitter and Flickr updates from one place – Learn 
 more!http://clk.atdmt.com/UKM/go/137984870/direct/01/


[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread kgosser

That's a good point, Josh. I thought of that earlier, but I wanted to
make sure this was the best way. For only passing two params, that's
not that bad of an idea, but I was checking to see if there was a best
practice here, like hopefully passing the params through somehow.

On Apr 16, 5:04 pm, Josh Nathanson joshnathan...@gmail.com wrote:
 You could do something like:

 a rel=val1_val2 // use a delimiter that makes sense for your values

 Then split the rel:

 var arr = this.rel.split('_'), val1 = arr[0], val2 = arr[1];

 removeDept( val1, val2 );

 -- Josh

 -Original Message-
 From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On

 Behalf Of kgosser
 Sent: Thursday, April 16, 2009 2:47 PM
 To: jQuery (English)
 Subject: [jQuery] passing more than 1 param via click()?

 Hey all,

 Not really sure how to ask this, so I'm sorry if my title is mis-
 leading. It is also why I wasn't able to find much searching, so I'm
 sorry if it's answered already.

 Basically, the code I inherited was this:

 a
      href=#drop
      class=edit-link
      onclick=
           removeDept('c:out value=${key} /','c:out value=$
 {name} /');
           return false;
 Remove Department/a

 And that is in an iteration, so the two values passed to the
 removeDept function are always dynamic.

 I'm trying to handle this in the document.ready(). Normally, I throw
 the would-be dynamic param passed as a rel tag on an anchor, and
 that's how I retrieve things when I clean up code like this.

 However, I'm scratching my head for the *best* way to handle this with
 the two params now... How do you guys recommend I handle something
 like that?

 $(document).ready(function() {
         $(.edit-link).click(function(){
                removeDept($(this).attr(rel),$(this).attr(rel));
                return false;
         });
 });

 Obviously I can't have two rel attributes :)

 Thanks in advance.


[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread Joseph Le Brech

you can also make custom attributes, they don't have to be called rel so you 
can have as many attributes as you want.

 Date: Thu, 16 Apr 2009 15:15:44 -0700
 Subject: [jQuery] Re: passing more than 1 param via click()?
 From: kgos...@gmail.com
 To: jquery-en@googlegroups.com
 
 
 That's a good point, Josh. I thought of that earlier, but I wanted to
 make sure this was the best way. For only passing two params, that's
 not that bad of an idea, but I was checking to see if there was a best
 practice here, like hopefully passing the params through somehow.
 
 On Apr 16, 5:04 pm, Josh Nathanson joshnathan...@gmail.com wrote:
  You could do something like:
 
  a rel=val1_val2 // use a delimiter that makes sense for your values
 
  Then split the rel:
 
  var arr = this.rel.split('_'), val1 = arr[0], val2 = arr[1];
 
  removeDept( val1, val2 );
 
  -- Josh
 
  -Original Message-
  From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On
 
  Behalf Of kgosser
  Sent: Thursday, April 16, 2009 2:47 PM
  To: jQuery (English)
  Subject: [jQuery] passing more than 1 param via click()?
 
  Hey all,
 
  Not really sure how to ask this, so I'm sorry if my title is mis-
  leading. It is also why I wasn't able to find much searching, so I'm
  sorry if it's answered already.
 
  Basically, the code I inherited was this:
 
  a
   href=#drop
   class=edit-link
   onclick=
removeDept('c:out value=${key} /','c:out value=$
  {name} /');
return false;
  Remove Department/a
 
  And that is in an iteration, so the two values passed to the
  removeDept function are always dynamic.
 
  I'm trying to handle this in the document.ready(). Normally, I throw
  the would-be dynamic param passed as a rel tag on an anchor, and
  that's how I retrieve things when I clean up code like this.
 
  However, I'm scratching my head for the *best* way to handle this with
  the two params now... How do you guys recommend I handle something
  like that?
 
  $(document).ready(function() {
  $(.edit-link).click(function(){
 removeDept($(this).attr(rel),$(this).attr(rel));
 return false;
  });
  });
 
  Obviously I can't have two rel attributes :)
 
  Thanks in advance.

_
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/

[jQuery] Re: passing more than 1 param via click()?

2009-04-16 Thread Michael Geary

I must be missing something obvious, but it sounds like you're not just
working with some predetermined HTML, but you have the flexibility to tweak
that HTML code, is that right?

Then why can't you generate this as part of your HTML page:

script type=text/javascript
// initialize some variables here
/script

That *is* HTML code, isn't it?

-Mike

 From: kgosser
 
 I have two values that are only found in a loop in the HTML. 
 They need to be passed to the single function in the document.ready().
 
 I can't set them in the JavaScript. I have to find them 
 somehow in the HTML. Whether I find them as hidden inputs or 
 something, or as tags to the anchor, or as params passed in 
 somehow. I'm not sure what's best.



[jQuery] Re: passing elem id to a JS function...

2009-04-15 Thread mkmanning

 var img_top  = $(#+curr_img);

On Apr 15, 8:57 am, kali maya778...@yahoo.com wrote:
 hi, am trying to do image-hide/img-show with jQuery (now use 'regular'
 JavaScript DOM-scripting..  want to switch to jQuery..  but am having
 some difficulties:

 I have this function-call in interface:

   get_img('photo1','nav1','navAll1','photo2','nav2','navAll2')

 in function -- old way:

 function get_img
 (curr_img,curr_nav,curr_navAll,new_img,new_nav,new_navAll)  {
         var img_top    = document.getElementById(curr_img);
         var img_new    = document.getElementById(new_img);    //  etc..

 how do I do this in jQuery?  I tried:

         var img_top    = $(#curr_img);
         var img_top    = $(curr_img);

 neither one of these is working..  and worst problem is I don't get
 errors in Firefox Error Console (jQuery syntax errors don't show in FF
 Error Console...  is there a place where you can check your jQuery
 syntax??)

 the element id's are passed to the function as string values..  so how
 do I add this string value to a wrapper like this

     $('# id passed to function')

 thank you...

 thank you very much...


[jQuery] Re: passing variables to a Jquery function

2009-03-31 Thread Abdullah Rubiyath

Hi,

I believe you can use the following approach:

Since you are requesting to another page, you can use the server-side
script (PHP) to return the id, type, and success message in JSON
format and then use them from jQuery, and instead of $.get, you can
use $.getJSON or $.ajax, Using this approach would also allow you to
show an error message should any error occur in server side.

http://docs.jquery.com/Ajax/jQuery.getJSON
http://docs.jquery.com/Ajax/jQuery.ajax

Also,  just a thought, using class 'doit' instead of id would allow to
you assign it to multiple Tags/elements on the page.

[html]
a href=something.php?id=123type=456 class=doit title=Do itdo
it/a

a href=something.php?id=788type=457 class=doit title=Do itdo
it/a

[js]

$(.doit).click(function(){
   var $this = $(this);  // store this reference for future use
   $.getJSON(this.href, function(data) {
if( data.success == '1') {
//  successful from server-side
$this.replaceWith('I\'ve been there (a href=something.undo.php?
id='+data.id+'type='+data.type+'undo/a)');
 }  else {
// not successful, show error or do something else
 }
   });
return false;
});

[php /server-side script]

// process the request and then IF Successful, then echo in JSON
format,
header('Content-Type: text/plain');
echo '{ success : 1 , id : '.$_GET['id'].' , type: .$_GET
['type'].' }';
// or you can use json_encode (requires PHP 5.2)
exit;


// PHP - json_encode,
http://ca.php.net/json_encode


There are several other alternative approach... I hope it helps,


Thanks,
Abdullah.

On Mar 30, 10:44 am, Peter Van Dijck petervandi...@gmail.com wrote:
 Hi all,I couldn't find a good answer to this, although it has probably been
 answered before, apologies!

 I have a link
 a id=doit href=/bla/something.php?id=123type=456do it/a

 And some jQuery code

 $(#doit).click(function(){ // upon click
 $.get(this.href); // call the URL
 $('#doit').replaceWith(I've been there (a
 href=/bla/something.undo.php?id=123type=456'undo/a));
 return false;
  });

 My problem is that I want to populate the URL that's in replaceWith with
 the correct id, depending on the id that was in the original link. I've
 thought of using a fake attribute in the link somehow (a type=456
 id=doit), but I can't seem to get it to work, and I'm not sure this is the
 right approach...

 What would be the jquery-like best way to do this?

 Thanks!
 Peter

 --
 me:http://petervandijck.com
 blog:http://poorbuthappy.com/ease/
 global UX consulting:http://290s.com
 free travel guides:http://poorbuthappy.com
 Belgium: (+32) 03/325 88 70
 Skype id: peterkevandijck


[jQuery] Re: Passing JSON objects to a Web Method

2009-02-28 Thread Mahesh

Hi Dave,
I'm using .NET 2.0.
And the web method is working fine with static parameters.
I could find a temporary solution of passing the JSON object as a
string and parsing the string into my .NET object using an open source
library Json.NET.
This way it works, but I'd be glad to avoid the 2 additional steps
that I have to carry out.

Regards,
Mahesh Dedhia.

On Feb 27, 7:25 pm, David Meiser dmei...@gmail.com wrote:
 Mahesh,

 A few things, while I'm remembering:
 1) Are you using .NET 3.5?  The method I gave you will (probably) only work
 with 3.5, although it might work with 3.0.

 2) Make sure you have the following before  the class in your ASMX or ASPX
 file:  [System.Web.Script.Services.ScriptService] (I believe this is new to
 3.5, and is necessary to call your WebService via javascript)

 Does your web method return data if you pass in static data (eg - data:
 {'fname':'John','lname':'Doe'} in your data declaration on the JQuery
 side)?

 On Fri, Feb 27, 2009 at 7:05 AM, Mahesh mrded...@gmail.com wrote:

  Hey Dave,
  Yes, I'm using ASP.NET web method inside an ASPX page.
  I tried your solution, but didn't work.
  Here, the code that I used.

  Default.js
   function Call() {

     var person = { fname : John,
                    lname  : Doe};

     $.ajax({
       type: POST,
       url: Default.aspx/WebMethod,
       //data: {},
       data: person,
        contentType: application/json; charset=utf-8,
        dataType: json,
       success: function(msg) {
         alert('Successful');
       }
     });
   };

  Default.aspx.cs
         [WebMethod]
         public static object WebMethod(string fname, string lname)
         {
             return new { fname = fname, lname = lname };
         }

  Didn't work..
  Apart from that, isn't there a way to recognize the JSON object as
  Object and type-cast it to a similar .NET object?
  I found something here,

 http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a...
  But it is using WCF which I don't want to.

  Regards,
  Mahesh.

  On Feb 26, 11:00 pm, David Meiser dmei...@gmail.com wrote:
   Are you talking about an ASP.NET web method?

   If you are, I think that you'll find it pretty easy using this:

               $.ajax({
                   type: POST,
                   contentType: application/json; charset=utf-8,
                   url: myWebService.asmx/myWebMethod,
                   data: myJSONObject
                   dataType: json,
                   success: function(json) { // do Stuff }
               });

   Just make sure that myWebMethod takes each item in the JSON object as a
   parameter and everything should work pretty well.

   Good luck!
   - Dave

   On Thu, Feb 26, 2009 at 9:45 AM, Mahesh mrded...@gmail.com wrote:

Hello,
How do I pass a JSON object to a server side web method as a
parameter?

For example:
I have the following JSON object.
var person = { firstName : John,
                   lastName  : Doe,
                   age       : 23 };

and I want to pass this object in the data: {} block.
Is it possible?

Regards,
Mahesh.


[jQuery] Re: Passing JSON objects to a Web Method

2009-02-28 Thread David Meiser
Mahesh,

If your object is already in JSON, there's really no need to use something
like Json.NET.  On the client, you could just parse out the JSON object
using eval statements or jQuery's JSON functions, but that's not a good
solution.

Something that popped out at me when I was rereading is that ASP.NET takes
the JSON in a string prior to consuming it.  What you're passing in is a
JSON object.  So, I'm wondering if ASP.NET isn't punting and producing an
error in your IIS logfiles.  Check this [1] website for more details.

[1]
http://weblogs.asp.net/sanjeevagarwal/archive/2008/07/29/Dynamically-create-ASP.NET-user-control-using-JQuery-and-JSON-enabled-Ajax-Web-Service.aspx

Good luck!
-- Dave

On Sat, Feb 28, 2009 at 8:20 AM, Mahesh mrded...@gmail.com wrote:


 Hi Dave,
 I'm using .NET 2.0.
 And the web method is working fine with static parameters.
 I could find a temporary solution of passing the JSON object as a
 string and parsing the string into my .NET object using an open source
 library Json.NET.
 This way it works, but I'd be glad to avoid the 2 additional steps
 that I have to carry out.

 Regards,
 Mahesh Dedhia.

 On Feb 27, 7:25 pm, David Meiser dmei...@gmail.com wrote:
  Mahesh,
 
  A few things, while I'm remembering:
  1) Are you using .NET 3.5?  The method I gave you will (probably) only
 work
  with 3.5, although it might work with 3.0.
 
  2) Make sure you have the following before  the class in your ASMX or
 ASPX
  file:  [System.Web.Script.Services.ScriptService] (I believe this is new
 to
  3.5, and is necessary to call your WebService via javascript)
 
  Does your web method return data if you pass in static data (eg - data:
  {'fname':'John','lname':'Doe'} in your data declaration on the JQuery
  side)?
 
  On Fri, Feb 27, 2009 at 7:05 AM, Mahesh mrded...@gmail.com wrote:
 
   Hey Dave,
   Yes, I'm using ASP.NET web method inside an ASPX page.
   I tried your solution, but didn't work.
   Here, the code that I used.
 
   Default.js
function Call() {
 
  var person = { fname : John,
 lname  : Doe};
 
  $.ajax({
type: POST,
url: Default.aspx/WebMethod,
//data: {},
data: person,
 contentType: application/json; charset=utf-8,
 dataType: json,
success: function(msg) {
  alert('Successful');
}
  });
};
 
   Default.aspx.cs
  [WebMethod]
  public static object WebMethod(string fname, string lname)
  {
  return new { fname = fname, lname = lname };
  }
 
   Didn't work..
   Apart from that, isn't there a way to recognize the JSON object as
   Object and type-cast it to a similar .NET object?
   I found something here,
 
  http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a.
 ..
   But it is using WCF which I don't want to.
 
   Regards,
   Mahesh.
 
   On Feb 26, 11:00 pm, David Meiser dmei...@gmail.com wrote:
Are you talking about an ASP.NET web method?
 
If you are, I think that you'll find it pretty easy using this:
 
$.ajax({
type: POST,
contentType: application/json; charset=utf-8,
url: myWebService.asmx/myWebMethod,
data: myJSONObject
dataType: json,
success: function(json) { // do Stuff }
});
 
Just make sure that myWebMethod takes each item in the JSON object as
 a
parameter and everything should work pretty well.
 
Good luck!
- Dave
 
On Thu, Feb 26, 2009 at 9:45 AM, Mahesh mrded...@gmail.com wrote:
 
 Hello,
 How do I pass a JSON object to a server side web method as a
 parameter?
 
 For example:
 I have the following JSON object.
 var person = { firstName : John,
lastName  : Doe,
age   : 23 };
 
 and I want to pass this object in the data: {} block.
 Is it possible?
 
 Regards,
 Mahesh.



[jQuery] Re: Passing JSON objects to a Web Method

2009-02-27 Thread Mahesh

Hey Dave,
Yes, I'm using ASP.NET web method inside an ASPX page.
I tried your solution, but didn't work.
Here, the code that I used.

Default.js
  function Call() {

var person = { fname : John,
   lname  : Doe};

$.ajax({
  type: POST,
  url: Default.aspx/WebMethod,
  //data: {},
  data: person,
  contentType: application/json; charset=utf-8,
  dataType: json,
  success: function(msg) {
alert('Successful');
  }
});
  };

Default.aspx.cs
[WebMethod]
public static object WebMethod(string fname, string lname)
{
return new { fname = fname, lname = lname };
}

Didn't work..
Apart from that, isn't there a way to recognize the JSON object as
Object and type-cast it to a similar .NET object?
I found something here,
http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a-WCF-service-with-jQuery.aspx
But it is using WCF which I don't want to.

Regards,
Mahesh.

On Feb 26, 11:00 pm, David Meiser dmei...@gmail.com wrote:
 Are you talking about an ASP.NET web method?

 If you are, I think that you'll find it pretty easy using this:

             $.ajax({
                 type: POST,
                 contentType: application/json; charset=utf-8,
                 url: myWebService.asmx/myWebMethod,
                 data: myJSONObject
                 dataType: json,
                 success: function(json) { // do Stuff }
             });

 Just make sure that myWebMethod takes each item in the JSON object as a
 parameter and everything should work pretty well.

 Good luck!
 - Dave

 On Thu, Feb 26, 2009 at 9:45 AM, Mahesh mrded...@gmail.com wrote:

  Hello,
  How do I pass a JSON object to a server side web method as a
  parameter?

  For example:
  I have the following JSON object.
  var person = { firstName : John,
                     lastName  : Doe,
                     age       : 23 };

  and I want to pass this object in the data: {} block.
  Is it possible?

  Regards,
  Mahesh.


[jQuery] Re: Passing JSON objects to a Web Method

2009-02-27 Thread David Meiser
Mahesh,

A few things, while I'm remembering:
1) Are you using .NET 3.5?  The method I gave you will (probably) only work
with 3.5, although it might work with 3.0.

2) Make sure you have the following before  the class in your ASMX or ASPX
file:  [System.Web.Script.Services.ScriptService] (I believe this is new to
3.5, and is necessary to call your WebService via javascript)

Does your web method return data if you pass in static data (eg - data:
{'fname':'John','lname':'Doe'} in your data declaration on the JQuery
side)?

On Fri, Feb 27, 2009 at 7:05 AM, Mahesh mrded...@gmail.com wrote:


 Hey Dave,
 Yes, I'm using ASP.NET web method inside an ASPX page.
 I tried your solution, but didn't work.
 Here, the code that I used.

 Default.js
  function Call() {

var person = { fname : John,
   lname  : Doe};

$.ajax({
  type: POST,
  url: Default.aspx/WebMethod,
  //data: {},
  data: person,
   contentType: application/json; charset=utf-8,
   dataType: json,
  success: function(msg) {
alert('Successful');
  }
});
  };

 Default.aspx.cs
[WebMethod]
public static object WebMethod(string fname, string lname)
{
return new { fname = fname, lname = lname };
}

 Didn't work..
 Apart from that, isn't there a way to recognize the JSON object as
 Object and type-cast it to a similar .NET object?
 I found something here,

 http://www.dennydotnet.com/post/2008/03/03/Passing-a-JSON-object-to-a-WCF-service-with-jQuery.aspx
 But it is using WCF which I don't want to.

 Regards,
 Mahesh.

 On Feb 26, 11:00 pm, David Meiser dmei...@gmail.com wrote:
  Are you talking about an ASP.NET web method?
 
  If you are, I think that you'll find it pretty easy using this:
 
  $.ajax({
  type: POST,
  contentType: application/json; charset=utf-8,
  url: myWebService.asmx/myWebMethod,
  data: myJSONObject
  dataType: json,
  success: function(json) { // do Stuff }
  });
 
  Just make sure that myWebMethod takes each item in the JSON object as a
  parameter and everything should work pretty well.
 
  Good luck!
  - Dave
 
  On Thu, Feb 26, 2009 at 9:45 AM, Mahesh mrded...@gmail.com wrote:
 
   Hello,
   How do I pass a JSON object to a server side web method as a
   parameter?
 
   For example:
   I have the following JSON object.
   var person = { firstName : John,
  lastName  : Doe,
  age   : 23 };
 
   and I want to pass this object in the data: {} block.
   Is it possible?
 
   Regards,
   Mahesh.



[jQuery] Re: Passing array to $.ajax()

2009-02-27 Thread gaz

Have recently found a solution to this problem:

$.post() accepts a JavaScript object for post data e.g. {name1 :
value1, name2 : value2}, but you need to specify the same object
property multiple times.
Therefore you can create this property once, put an array into it and
then push your values into that array.

assuming vars 'url', 'postData', 'name' and 'value' already declared:

// is php array syntax being used? i.e. ends with []
if(name.charAt(name.length -2) == '['   name.charAt(name.length -1)
== ']') {
// create array if needed
if(postData[name] === undefined) {
postData[name] = [];
}
// push value onto array
postData[name].push(value);
}
// not using php array syntax so add in normal way
else postData[name] = value;

// post to server
$.post(url, postData, function(data) {
// handle response
});

Hope this helps.

On Feb 11, 6:43 am, Konstantin Mirin konstantin.mi...@gmail.com
wrote:
 I need to pass array to $.ajax() function and get this array on the server
 side.
 If doing this manually, I should get: script.php?arr[]=val1arr[]=val2
 $.ajax() only encodes like script.php?arr=val1arr=val2 and I get only the
 last value on the server side... any ideas how to do it without custom
 function?

 Best regards,
 Konstantin Mirin

 mailto:konstantin.mi...@gmail.com
 mailto:i...@konstantin.takeforce.net


[jQuery] Re: Passing JSON objects to a Web Method

2009-02-26 Thread David Meiser
Are you talking about an ASP.NET web method?

If you are, I think that you'll find it pretty easy using this:

$.ajax({
type: POST,
contentType: application/json; charset=utf-8,
url: myWebService.asmx/myWebMethod,
data: myJSONObject
dataType: json,
success: function(json) { // do Stuff }
});

Just make sure that myWebMethod takes each item in the JSON object as a
parameter and everything should work pretty well.

Good luck!
- Dave

On Thu, Feb 26, 2009 at 9:45 AM, Mahesh mrded...@gmail.com wrote:


 Hello,
 How do I pass a JSON object to a server side web method as a
 parameter?

 For example:
 I have the following JSON object.
 var person = { firstName : John,
lastName  : Doe,
age   : 23 };

 and I want to pass this object in the data: {} block.
 Is it possible?

 Regards,
 Mahesh.



[jQuery] Re: Passing array to $.ajax()

2009-02-11 Thread James

Can you submit your request via POST? If so, try using:
serializeArray(): http://docs.jquery.com/Ajax/serializeArray
and inserting the result as the data part of your AJAX request.

else, see if
serialize(): http://docs.jquery.com/Ajax/serialize
can do the work for you.

On Feb 10, 8:43 pm, Konstantin Mirin konstantin.mi...@gmail.com
wrote:
 I need to pass array to $.ajax() function and get this array on the server
 side.
 If doing this manually, I should get: script.php?arr[]=val1arr[]=val2
 $.ajax() only encodes like script.php?arr=val1arr=val2 and I get only the
 last value on the server side... any ideas how to do it without custom
 function?

 Best regards,
 Konstantin Mirin

 mailto:konstantin.mi...@gmail.com
 mailto:i...@konstantin.takeforce.net


[jQuery] Re: Passing a Index to a function

2009-02-10 Thread tres

var li = $('ul li');

li.bind('click', function() {
alert(li.index(this));
});

...works for me. Also, if you are calling jQuery on the same set of
objects more than once, it is wise to set a reference to it instead of
re calling it more than once. Instead something such as this:

$('ul li').bind('click', function() {
alert($('ul li').index(this));
});

This makes your code faster - which is unnoticeable in this example,
but when you have 2000 lines of it going on, you bet your sweet ass :)
- and easier to change in the future.

-Trey

On Feb 10, 3:37 pm, Pedram pedram...@gmail.com wrote:
 I came back to my COde An I found your code fit in mine I am not going
 to use rowIndex because My Plugin it should work for every selector so
 what I atually want to do to get the selector name and bind an event
 to it and sent it to a function and also pass the index to the
 function and the reason I'm doing this is because I have some
 recursive functions in it and I badly needed this to be done .

   var RowSet={
     close:false,
         eventClass:eventClass,
         eventType:click,
         ActionSelector:tr
   }

   function clickFunc(e){
           console.log(e.data.Index);
   }
   $.fn.RowEffectByEvent=function(options){
         RowSet = jQuery.extend({},RowSet,options);
         return this.each(function(){
           oo=$(this);
           var k=(settings.header) ? :not(:first) : ;
           $(RowSet.ActionSelector+k,oo).each(function(index){
                         
 $(this).bind(RowSet.eventType,{Index:index},clickFunc);
           });
         });
   };

 this is what I actually wanted to do thanks a lot guys you helped me
 alot and also RobG A appreciate it . thanks for the Tutorial also.

 On Feb 9, 1:26 pm, Ricardo Tomasi ricardob...@gmail.com wrote:

  $(table tr).each(function( index ){
    $(this).click(function(){
       alert('I am TR number ' + index);
    });

  });

  the index() function works on a collection of elements, so you'd have
  to get them first:

  $('table tr').click(function(){
     alert( $(this).parent().children().index(this) );

  });

  On Feb 9, 5:48 pm, Pedram pedram...@gmail.com wrote:

   How COme we could not have access inside the BIND with THIS !! I'm
   Confused

   On Feb 9, 7:16 am, Pedram pedram...@gmail.com wrote:

I check these two solutions it didn't work ...

On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote:

 On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:

  Dear folk,
  I want to get the index of the TR and send it to the Function , I
  don't know how to it . this is what I'm trying to do

  $(table 
  tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

 The DOM 2 HTML TR.rowIndex property should do the job.

 --
 Rob


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread Pedram

I check these two solutions it didn't work ...

On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote:
 On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:

  Dear folk,
  I want to get the index of the TR and send it to the Function , I
  don't know how to it . this is what I'm trying to do

  $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

 The DOM 2 HTML TR.rowIndex property should do the job.

 --
 Rob


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread Pedram

How COme we could not have access inside the BIND with THIS !! I'm
Confused

On Feb 9, 7:16 am, Pedram pedram...@gmail.com wrote:
 I check these two solutions it didn't work ...

 On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote:

  On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:

   Dear folk,
   I want to get the index of the TR and send it to the Function , I
   don't know how to it . this is what I'm trying to do

   $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

  The DOM 2 HTML TR.rowIndex property should do the job.

  --
  Rob


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread Ricardo Tomasi

$(table tr).each(function( index ){
  $(this).click(function(){
 alert('I am TR number ' + index);
  });
});

the index() function works on a collection of elements, so you'd have
to get them first:

$('table tr').click(function(){
   alert( $(this).parent().children().index(this) );
});

On Feb 9, 5:48 pm, Pedram pedram...@gmail.com wrote:
 How COme we could not have access inside the BIND with THIS !! I'm
 Confused

 On Feb 9, 7:16 am, Pedram pedram...@gmail.com wrote:

  I check these two solutions it didn't work ...

  On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote:

   On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:

Dear folk,
I want to get the index of the TR and send it to the Function , I
don't know how to it . this is what I'm trying to do

$(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

   The DOM 2 HTML TR.rowIndex property should do the job.

   --
   Rob


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread RobG



On Feb 10, 5:48 am, Pedram pedram...@gmail.com wrote:
 How COme we could not have access inside the BIND with THIS !! I'm
 Confused

I don't know why you want to make it so complex.  Consider:

  $(table tr).click(function(){alert(this.rowIndex);});

If you want to call a function:

  $(table tr).click(function(){clickFunc(this.rowIndex)});

If you want to use bind (and I don't see the point, but anyhow...)

  $(table tr).bind(click, function() {
clickFunc(this.rowIndex);
   });

  function clickFunc(rowIndex) {
alert(rowIndex);
  }


or, to get closer to your original:

  $(table tr).bind(click, {prop1:'property 1', prop2: 'property
2'}, clickFunc);

and in clickFunc:

  function clickFunc(e) {
alert(this.rowIndex);
  }


Going further:

  $(table tr).bind(click, {prop1:'property 1', prop2: 'property
2'}, clickFunc);

  function clickFunc(e) {
alert(this.rowIndex + '\n' + e.data.prop1);
  }

See? No selector needed, the row has a rowIndex property that tells
you which row it is in the table.  If you have a thead element, its
rows are counted in the rowIndex and rows in tfoot include all the
rows above (i.e. it is the index in the entire table).


--
Rob


[jQuery] Re: passing in an index to a function, then toggle an element based on the index

2009-02-09 Thread Mike Alsup

 I am invoking a javascript function with an index. Inside the
 javascript function, I am constructing the identifier for the element
 using the index. For example, if the index is 10, then the class name
 of the element is elem-10. Now I need to toggle the display style of
 that element. How can I do this?
 $(div.elem-+index).toggle() is not working obviously.

Not obvious to me why it isn't working.  Are you sure the selector is
finding the element?

console.log( $(div.elem-+index).length );

Or maybe you could post a link?


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread Pedram

thanks ROb , I Appreciate it , I'm writing a Plugin I am going to use
the last part of your code , that I'm fine with that. great. THanks
other guys , my Problem Is solved

On Feb 9, 3:44 pm, RobG rg...@iinet.net.au wrote:
 On Feb 10, 5:48 am, Pedram pedram...@gmail.com wrote:

  How COme we could not have access inside the BIND with THIS !! I'm
  Confused

 I don't know why you want to make it so complex.  Consider:

   $(table tr).click(function(){alert(this.rowIndex);});

 If you want to call a function:

   $(table tr).click(function(){clickFunc(this.rowIndex)});

 If you want to use bind (and I don't see the point, but anyhow...)

   $(table tr).bind(click, function() {
     clickFunc(this.rowIndex);
    });

   function clickFunc(rowIndex) {
     alert(rowIndex);
   }

 or, to get closer to your original:

   $(table tr).bind(click, {prop1:'property 1', prop2: 'property
 2'}, clickFunc);

 and in clickFunc:

   function clickFunc(e) {
     alert(this.rowIndex);
   }

 Going further:

   $(table tr).bind(click, {prop1:'property 1', prop2: 'property
 2'}, clickFunc);

   function clickFunc(e) {
     alert(this.rowIndex + '\n' + e.data.prop1);
   }

 See? No selector needed, the row has a rowIndex property that tells
 you which row it is in the table.  If you have a thead element, its
 rows are counted in the rowIndex and rows in tfoot include all the
 rows above (i.e. it is the index in the entire table).

 --
 Rob


[jQuery] Re: Passing a Index to a function

2009-02-09 Thread Pedram

I came back to my COde An I found your code fit in mine I am not going
to use rowIndex because My Plugin it should work for every selector so
what I atually want to do to get the selector name and bind an event
to it and sent it to a function and also pass the index to the
function and the reason I'm doing this is because I have some
recursive functions in it and I badly needed this to be done .


  var RowSet={
close:false,
eventClass:eventClass,
eventType:click,
ActionSelector:tr
  }

  function clickFunc(e){
  console.log(e.data.Index);
  }
  $.fn.RowEffectByEvent=function(options){
RowSet = jQuery.extend({},RowSet,options);
return this.each(function(){
  oo=$(this);
  var k=(settings.header) ? :not(:first) : ;
  $(RowSet.ActionSelector+k,oo).each(function(index){
$(this).bind(RowSet.eventType,{Index:index},clickFunc);
  });
});
  };

this is what I actually wanted to do thanks a lot guys you helped me
alot and also RobG A appreciate it . thanks for the Tutorial also.


On Feb 9, 1:26 pm, Ricardo Tomasi ricardob...@gmail.com wrote:
 $(table tr).each(function( index ){
   $(this).click(function(){
      alert('I am TR number ' + index);
   });

 });

 the index() function works on a collection of elements, so you'd have
 to get them first:

 $('table tr').click(function(){
    alert( $(this).parent().children().index(this) );

 });

 On Feb 9, 5:48 pm, Pedram pedram...@gmail.com wrote:

  How COme we could not have access inside the BIND with THIS !! I'm
  Confused

  On Feb 9, 7:16 am, Pedram pedram...@gmail.com wrote:

   I check these two solutions it didn't work ...

   On Feb 8, 11:42 pm, RobG rg...@iinet.net.au wrote:

On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:

 Dear folk,
 I want to get the index of the TR and send it to the Function , I
 don't know how to it . this is what I'm trying to do

 $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

The DOM 2 HTML TR.rowIndex property should do the job.

--
Rob


[jQuery] Re: Passing a Index to a function

2009-02-08 Thread Geuis

$(table tr).click(function() {

clickFunc($('table tr').index(this);

});

On Feb 8, 10:54 pm, Pedram pedram...@gmail.com wrote:
 Dear folk,
 I want to get the index of the TR and send it to the Function , I
 don't know how to it . this is what I'm trying to do

 $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

 function clickFunc(event){
           console.log(event.data.IndexName);

 }


[jQuery] Re: Passing a Index to a function

2009-02-08 Thread RobG



On Feb 9, 4:54 pm, Pedram pedram...@gmail.com wrote:
 Dear folk,
 I want to get the index of the TR and send it to the Function , I
 don't know how to it . this is what I'm trying to do

 $(table tr).bind(click,{IndexName:$(this).index(this)},clickFunc)

The DOM 2 HTML TR.rowIndex property should do the job.


--
Rob


[jQuery] Re: Passing an HTML page fragment as an Ajax XML field

2009-01-28 Thread JS London

Many thanks jay for your responses.

The first one - using load() to filter the response -  unfortunately
load() will then discard the remainder of the XML response. I want to
pass the HTML fragment as part of a larger XML message and use the
data from the other fields as well. I would have to make the request
twice (once for the HTML fragment, once for the XML fields and things
will have changed server-side in the interim). I am using $.ajax(). I
haven't testing load() but I suspect in any case it may require a text
(rather than XML response) from the server to work, much like $.ajax
().

In your second example, yes this works because you are passing HTML to
the after() method (provided of course you use valid HTML element
tags, such as span or div rather than frag). However the problem I
have is passing XML to after() rather than HTML

To demonstrate, I quickly wrote up the example above into code and
tested it. This is the XML file (response.xml) sitting on the
server:

?xml version=1.0?
response
   cityid2/cityid
   frag
  div class=citybox
 h2 class=citytitleCity of London/h2
 p class=descLondon is on the River Thames/p
  /div
   /frag
/response

And this is the requesting webpage:

html
head
script type='text/javascript' src=jquery.js/script
script type='text/javascript'
   $(function(){
  $(#button).click(function(){
 $.ajax ({
url: response.xml,
success: function(data, status) {
   alert (Received City ID +$(data).find(cityid).text
());
   $(#title).after($(data).find(frag).children());
}
 });
  });
   });
/script
/head
body
p id=titleCities of the World/p
input type=button id=button value=Get
/body

The above receives the XML message, displays the city ID correctly,
but then fails to insert the HTML fragment into the webpage...


[jQuery] Re: Passing an HTML page fragment as an Ajax XML field

2009-01-27 Thread jay

You could do it this way:

http://docs.jquery.com/Ajax/load

You can pass a selector to load() to pick what you want from the
response.

On Jan 27, 7:29 am, JS London jus...@alphainitiatives.com wrote:
 Hi,

 I would like to pass an fragment of HTML as a field in my Ajax
 response and then insert this into the DOM. For example if part of the
 Ajax XML response (ajax_xml) is as follows:

 cityid2/cityid
 frag
    div class=cityboxh2 class=citytitleCity of London/h2p
 class=descLondon is on the River Thames/p/div
 /frag

 (I want to generate the fragment markup server-side for consistency.)

 I can extract the HTML fragment as follows:

 var frag=$(ajax_xml).find(frag).children();

 But when I come to insert it into the DOM, neither of these work:

 a. $(#myid).after(frag);
 b. $(#myid).after($(frag).html());

 (it states in the JQuery website documentation that (b) will not work)

 Is there a way of doing this without having to escape the original
 HTML fragment? (which I want to avoid)

 Any help much appreciated, many thanks
 JS, London


[jQuery] Re: Passing an HTML page fragment as an Ajax XML field

2009-01-27 Thread jay

You could also try changing frag to div class=frag instead.  For
example this worked in firefox but not IE:

body
script src=jquery.js/script
frag
   div class=cityboxh2 class=citytitleCity of London/h2p
class=descLondon is on the River Thames/p/div
/frag
hr/
div id=myid/div
script
var frag = $(frag).children();
$(#myid).after(frag);
/script
/body

When I switched frag to span, for example, it worked.

On Jan 27, 7:29 am, JS London jus...@alphainitiatives.com wrote:
 Hi,

 I would like to pass an fragment of HTML as a field in my Ajax
 response and then insert this into the DOM. For example if part of the
 Ajax XML response (ajax_xml) is as follows:

 cityid2/cityid
 frag
    div class=cityboxh2 class=citytitleCity of London/h2p
 class=descLondon is on the River Thames/p/div
 /frag

 (I want to generate the fragment markup server-side for consistency.)

 I can extract the HTML fragment as follows:

 var frag=$(ajax_xml).find(frag).children();

 But when I come to insert it into the DOM, neither of these work:

 a. $(#myid).after(frag);
 b. $(#myid).after($(frag).html());

 (it states in the JQuery website documentation that (b) will not work)

 Is there a way of doing this without having to escape the original
 HTML fragment? (which I want to avoid)

 Any help much appreciated, many thanks
 JS, London


[jQuery] Re: Passing vars to function

2009-01-13 Thread Maginot Junior
Hmm
thanks for the help!

This help me understand more of how jquery works, just to keep update, I did
the follow to workaround:

$(#artigos_listagem li:even).addClass('even');
$(#artigos_listagem li).mouseover(function(e){
$(this).css({
background: #aa
});
});
$(#artigos_listagem li).mouseout(function(e){
if ($(this).hasClass('even')) {

$(this).css({
background: '#E7EDF1'
});
} else {
$(this).css({
background: '#ff'
});
}
});


but I'll use the toggle function, looks  much better and smarter

best regards!


Maginot Júnior
the game of life
LPIC - CCNA - ¿Designer?


On Tue, Jan 13, 2009 at 2:48 AM, seasoup seas...@gmail.com wrote:


 untested, but the point is you can pass an object as the second
 parameter of the .bind() function.  Doesn't work with the shortcuts as
 far as I know.  Then, you can access those object in the event.data
 property of the event passed into the function.

 $(#artigos_listagem li).mouseover(function(e){
var orgBg = $(this).css('background');
$(this).css({
background: #aa
});
});
 $(#artigos_listagem li).bind('mouseout', { 'orgBg' :
 orgBg}, function(e){
$(this).css({
background: e.data.orgBg
});
});

 I'm also not quite sure what you are attempting... it looks like those
 li are getting a mouseover/mouseout  function that sets the background
 to one color when rolling over and to another when rolling off.  If
 that is the case:

 $(#artigos_listagem li).toggle(function() {
  $(this).css({'background':'#aa'});
 },
 function() {
  $(this).css({'background':'#aa'});
 })

 If the colors aren't known beforehand, since you are setting it
 dynamically on li's with different background colors then you could
 save the current background color as a custom attribute using .attr()
 or as data on the object using .data()

 http://docs.jquery.com/Internals/jQuery.data



[jQuery] Re: Passing vars to function

2009-01-12 Thread Scott Sauyet


Maginot Junior wrote:

HI, I have a simples question, hope to get some answer...

Im having difficulty to pass vars to functions like: [ ... ]

$(#artigos_listagem li).mouseout(function(e){
$(this).css({
background: orgBg
});
});


Like you can see, inside the second function Im trying to use the orgBg 
vars, and I would like to pass like .mouseout(function(e, otherVar){


You won't be able to do it that simply, as the mouseout won't call it 
with your custom parameters.  But you can add a closure. [1]


This is completely untested, but I think something like this would work:

$(#artigos_listagem li).mouseout((function(bkground) {
return function(e){
$(this).css({background: bkground});
})(orgBg);
});

This syntax creates and immediately executes an anonymous function that
returns a function in a closure that includes your val as param.

(function(param) {return function() {...})(val)

There is no real reason except for explanations like the above to use 
the dummy variable bkground, so this is probably better once you 
understand what's happening above:


$(#artigos_listagem li).mouseout((function(orgBg) {
return function(e){
$(this).css({background: orgBg});
})(orgBg);
});

Cheers,

  -- Scott

[1] The first few references on Google are all pretty good: 
http://www.google.com/search?q=javascript+closure


[jQuery] Re: Passing vars to function

2009-01-12 Thread seasoup

untested, but the point is you can pass an object as the second
parameter of the .bind() function.  Doesn't work with the shortcuts as
far as I know.  Then, you can access those object in the event.data
property of the event passed into the function.

$(#artigos_listagem li).mouseover(function(e){
var orgBg = $(this).css('background');
$(this).css({
background: #aa
});
});
$(#artigos_listagem li).bind('mouseout', { 'orgBg' :
orgBg}, function(e){
$(this).css({
background: e.data.orgBg
});
});

I'm also not quite sure what you are attempting... it looks like those
li are getting a mouseover/mouseout  function that sets the background
to one color when rolling over and to another when rolling off.  If
that is the case:

$(#artigos_listagem li).toggle(function() {
  $(this).css({'background':'#aa'});
},
function() {
  $(this).css({'background':'#aa'});
})

If the colors aren't known beforehand, since you are setting it
dynamically on li's with different background colors then you could
save the current background color as a custom attribute using .attr()
or as data on the object using .data()

http://docs.jquery.com/Internals/jQuery.data


[jQuery] Re: passing args to a delegate

2008-12-15 Thread Jan Limpens

javascript just keeps amazing me more and more :)
thanks for the insight!

On Sat, Dec 13, 2008 at 8:49 PM, Jeffrey Kretz jeffkr...@hotmail.com wrote:

 Mike's suggestion involves creating a javascript closure.

 There are a number of good articles on closues.

 http://www.google.com/search?hl=enq=javascript+closuresrlz=1W1GGLL_en

 But essentially, when you create a function that has a reference to a value 
 outside of its scope, that function is created as a closure, with its own 
 context that has access to those variables, even when they've been changed on 
 the global scope.

 Try this:

 var x = 25;
 var fn = function(val){
   return function(){
  alert(val);
   };
 }(x);
 x = 30;
 fn();

 The alert will be for 25, rather than 30, as the closure has its own context 
 now for the x variable.

 The downside to closures is that handled incorrectly, they can cause memory 
 leaks.

 But review of the many articles on the subject will help keep that from 
 happening.

 JK


 -Original Message-
 From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On 
 Behalf Of Jan Limpens
 Sent: Saturday, December 13, 2008 2:28 PM
 To: jquery-en@googlegroups.com
 Subject: [jQuery] Re: passing args to a delegate


 while this might keep the browser from crashing, I wonder what values
 these parameters will have, when the event finally occurs. The ones I
 have passed the very first time? I thought they would have been
 destroyed by then, as we left this scope long ago ...
 But I'll try it out :), thanks!

 On Sat, Dec 13, 2008 at 3:22 AM, Mike Nichols nichols.mik...@gmail.com 
 wrote:

 Try this:
 success: function() { registerImageForms(id,key,type); }


 On Dec 12, 5:13 pm, Jan Limpens jan.limp...@gmail.com wrote:
 Hello,

 I have the following code:

 var registerImageForms = function(id, key, type) {
 var sizes = ['small', 'medium', 'large'];
 $('#panel-images fieldset:visible').remove();
 $.each(sizes, function(i, item) {
 var $clonedForm = $('#panel-images fieldset:hidden').clone();
 $(legend, $clonedForm).text(item);
 $([name='id'], $clonedForm).val(id);
 $([name='key'], $clonedForm).val(key);
 $([name='type'], $clonedForm).val(type);
 $([name='size'], $clonedForm).val(item);
 $(img, $clonedForm).attr('src', /imagem/article/ + key +
 / + item + .png);
 $(#panel-images).append($clonedForm);
 $(form, $clonedForm).ajaxForm({
 success: registerImageForms
 });
 $clonedForm.show();
 });

 };

 Success has no args, so everything is rendered empty, after posting
 the form. If I pass arguments as
 success: registerImageForms(id, key, type)

 The browser crashes and it makes sense, because at the time this
 fires, these identifiers mean nothing. But how do I pass them?

 --
 Jan



 --
 Jan





-- 
Jan


[jQuery] Re: passing this reference to setTimeout()

2008-12-15 Thread Mike Alsup

 I'm using jQuery.hover for a dropdown menu and I want to add a slight
 delay to mouseOut functions but I can't figure out how to pass the
 jQuery(this) reference into the setTimeout() function... can this be
 done?

 jQuery('li.drop').hover(
         function(){
                 jQuery(this).addClass('show');
         },
         function(){
                 var t = setTimeout( function(){ 
 jQuery(this).removeClass('show'); },
 1000);
         }
 );


jQuery('li.drop').hover(
function(){
jQuery(this).addClass('show');
},
function(){
var $this = jQuery(this);
setTimeout( function(){ $this.removeClass('show'); }, 1000);
}
)



[jQuery] Re: passing this reference to setTimeout()

2008-12-15 Thread ekallevig

Thanks!

On Dec 15, 11:59 am, Mike Alsup mal...@gmail.com wrote:
  I'm using jQuery.hover for a dropdown menu and I want to add a slight
  delay to mouseOut functions but I can't figure out how to pass the
  jQuery(this) reference into the setTimeout() function... can this be
  done?

  jQuery('li.drop').hover(
          function(){
                  jQuery(this).addClass('show');
          },
          function(){
                  var t = setTimeout( function(){ 
  jQuery(this).removeClass('show'); },
  1000);
          }
  );

 jQuery('li.drop').hover(
     function(){
         jQuery(this).addClass('show');
     },
     function(){
         var $this = jQuery(this);
         setTimeout( function(){ $this.removeClass('show'); }, 1000);
     }
 )


[jQuery] Re: passing args to a delegate

2008-12-13 Thread Jan Limpens

while this might keep the browser from crashing, I wonder what values
these parameters will have, when the event finally occurs. The ones I
have passed the very first time? I thought they would have been
destroyed by then, as we left this scope long ago ...
But I'll try it out :), thanks!

On Sat, Dec 13, 2008 at 3:22 AM, Mike Nichols nichols.mik...@gmail.com wrote:

 Try this:
 success: function() { registerImageForms(id,key,type); }


 On Dec 12, 5:13 pm, Jan Limpens jan.limp...@gmail.com wrote:
 Hello,

 I have the following code:

 var registerImageForms = function(id, key, type) {
 var sizes = ['small', 'medium', 'large'];
 $('#panel-images fieldset:visible').remove();
 $.each(sizes, function(i, item) {
 var $clonedForm = $('#panel-images fieldset:hidden').clone();
 $(legend, $clonedForm).text(item);
 $([name='id'], $clonedForm).val(id);
 $([name='key'], $clonedForm).val(key);
 $([name='type'], $clonedForm).val(type);
 $([name='size'], $clonedForm).val(item);
 $(img, $clonedForm).attr('src', /imagem/article/ + key +
 / + item + .png);
 $(#panel-images).append($clonedForm);
 $(form, $clonedForm).ajaxForm({
 success: registerImageForms
 });
 $clonedForm.show();
 });

 };

 Success has no args, so everything is rendered empty, after posting
 the form. If I pass arguments as
 success: registerImageForms(id, key, type)

 The browser crashes and it makes sense, because at the time this
 fires, these identifiers mean nothing. But how do I pass them?

 --
 Jan



-- 
Jan


[jQuery] Re: passing args to a delegate

2008-12-13 Thread Jeffrey Kretz

Mike's suggestion involves creating a javascript closure.

There are a number of good articles on closues.

http://www.google.com/search?hl=enq=javascript+closuresrlz=1W1GGLL_en

But essentially, when you create a function that has a reference to a value 
outside of its scope, that function is created as a closure, with its own 
context that has access to those variables, even when they've been changed on 
the global scope.

Try this:

var x = 25;
var fn = function(val){
   return function(){
  alert(val);
   };
}(x);
x = 30;
fn();

The alert will be for 25, rather than 30, as the closure has its own context 
now for the x variable.

The downside to closures is that handled incorrectly, they can cause memory 
leaks.

But review of the many articles on the subject will help keep that from 
happening.

JK


-Original Message-
From: jquery-en@googlegroups.com [mailto:jquery...@googlegroups.com] On Behalf 
Of Jan Limpens
Sent: Saturday, December 13, 2008 2:28 PM
To: jquery-en@googlegroups.com
Subject: [jQuery] Re: passing args to a delegate


while this might keep the browser from crashing, I wonder what values
these parameters will have, when the event finally occurs. The ones I
have passed the very first time? I thought they would have been
destroyed by then, as we left this scope long ago ...
But I'll try it out :), thanks!

On Sat, Dec 13, 2008 at 3:22 AM, Mike Nichols nichols.mik...@gmail.com wrote:

 Try this:
 success: function() { registerImageForms(id,key,type); }


 On Dec 12, 5:13 pm, Jan Limpens jan.limp...@gmail.com wrote:
 Hello,

 I have the following code:

 var registerImageForms = function(id, key, type) {
 var sizes = ['small', 'medium', 'large'];
 $('#panel-images fieldset:visible').remove();
 $.each(sizes, function(i, item) {
 var $clonedForm = $('#panel-images fieldset:hidden').clone();
 $(legend, $clonedForm).text(item);
 $([name='id'], $clonedForm).val(id);
 $([name='key'], $clonedForm).val(key);
 $([name='type'], $clonedForm).val(type);
 $([name='size'], $clonedForm).val(item);
 $(img, $clonedForm).attr('src', /imagem/article/ + key +
 / + item + .png);
 $(#panel-images).append($clonedForm);
 $(form, $clonedForm).ajaxForm({
 success: registerImageForms
 });
 $clonedForm.show();
 });

 };

 Success has no args, so everything is rendered empty, after posting
 the form. If I pass arguments as
 success: registerImageForms(id, key, type)

 The browser crashes and it makes sense, because at the time this
 fires, these identifiers mean nothing. But how do I pass them?

 --
 Jan



-- 
Jan



[jQuery] Re: passing args to a delegate

2008-12-12 Thread Mike Nichols

Try this:
success: function() { registerImageForms(id,key,type); }


On Dec 12, 5:13 pm, Jan Limpens jan.limp...@gmail.com wrote:
 Hello,

 I have the following code:

 var registerImageForms = function(id, key, type) {
     var sizes = ['small', 'medium', 'large'];
     $('#panel-images fieldset:visible').remove();
     $.each(sizes, function(i, item) {
         var $clonedForm = $('#panel-images fieldset:hidden').clone();
         $(legend, $clonedForm).text(item);
         $([name='id'], $clonedForm).val(id);
         $([name='key'], $clonedForm).val(key);
         $([name='type'], $clonedForm).val(type);
         $([name='size'], $clonedForm).val(item);
         $(img, $clonedForm).attr('src', /imagem/article/ + key +
 / + item + .png);
         $(#panel-images).append($clonedForm);
         $(form, $clonedForm).ajaxForm({
             success: registerImageForms
         });
         $clonedForm.show();
     });

 };

 Success has no args, so everything is rendered empty, after posting
 the form. If I pass arguments as
             success: registerImageForms(id, key, type)

 The browser crashes and it makes sense, because at the time this
 fires, these identifiers mean nothing. But how do I pass them?

 --
 Jan


[jQuery] Re: passing 'this' into getjson callback

2008-12-05 Thread Erik Beeson
I think anonymous functions are much easier to read and understand. They
also make scoping a bit cleaner. You can rewrite with named functions if it
makes sense for your application. This is untested, but should be close to
what you're asking:

jQuery( '#myButton' ).bind( 'click', function() {var theButton = this;
jQuery.getJSON( url, null, function( json ) {
// handle json stuff here. theButton is the DOM node of the clicked
element.
// or call handleResult(json, theButton); to pass the element to
handleResult
} );});

FYI, if this is your real code, this:

jQuery.getJSON( url, null, function( json ) { myProject.handleResult( json )
} );

Is the same as this:

jQuery.getJSON( url, null, myProject.handleResult );

Creating an anonymous function that just calls a function with the same
arguments is redundant. This probably isn't actually what you want in this
case though since you then can't pass the button reference.

--Erik


On Fri, Dec 5, 2008 at 2:16 AM, pramodx [EMAIL PROTECTED] wrote:


 Hi,

 On click of a button I am placing a json call in the following manner

 jQuery( '#myButton' ).bind( 'click', myProject.callJson );

 The callJson function calls the json parameters:

 jQuery.getJSON( url, null, function( json ) { myProject.handleResult
 ( json ) } );

 The handleResult function further takes me to someOtherFunction() as
 well.

 The issue is that all the while I need to keep on passing a reference
 to the clicked button through jQuery(this) so that I can manipulate it
 in someOtherFunction(). How do I do that? Any pointers would be very
 helpful.

 Thanks
 Pramod



[jQuery] Re: Passing a variable to a function

2008-10-02 Thread [EMAIL PROTECTED]

HI,

Thanks for your response, it's a good answer and works in the case you
describe.

Unfortunately I've got 2 more li's in between the clicked li and the
toggled li. The full code looks like this:

ul
li class=evdatedate/li
ll class=evnamea href=#name/a/li
li class=evregionRegion/li
li class=evlocLocation/li
li class=evsumEvent summary to be hidden and displayed/li

li class=evdatedate/li
ll class=evnamea href=#name/a/li
li class=evregionRegion/li
li class=evlocLocation/li
li class=evsumEvent summary to be hidden and displayed/li

/ul

Is there a way to say toggle next+2?

Andy

On Oct 1, 7:45 pm, MorningZ [EMAIL PROTECTED] wrote:
 So, and if am understanding correctly...  you have this html an are
 after some sort of accordion like behavior

 ul

     li class=evnameEvent 1 Name/li
     li class=evsumSummary of Event 1/li

     li class=evnameEvent 2 Name/li
     li class=evsumSummary of Event 2/li

     li class=evnameEvent 3 Name/li
     li class=evsumSummary of Event 3/li

     li class=evnameEvent 4 Name/li
     li class=evsumSummary of Event 4/li

     etc etc..
 /ul

 and you have evsum hidden by say:

 .evsum { display: none; }

 and you want to click on the evname and show the related evsum

 if thats the case, the jQuery could be like:

 $(document).ready(function() {
      $(.evname).click(function() {
           $(this).next().toggle();
      });

 });

 that would show (or hide, hence the use of toggle) the respective
 summary

 On Oct 1, 1:16 pm, andrewsquidge [EMAIL PROTECTED] wrote:

  Hi guys,

  I've been trying to get this literally all day! I just can't work it out.

  I've got this HTML:
  ul
  li class=evname 1 This is the event name /li
  li class=evsumsome text here/li
  /ul

  On click of li class=evname the li beneath should reveal. But because
  there are many of these ona page and they will be dynamic I need to set it
  to reveal only the relevant one.

  So my plan was to reveal the relevant li class=evsum in order. Here's
  the jquery:

          $(document).ready(function() {

                  $(li.evname).click(function() {
                          var id = this.id.replace('show_', );
                          $(#eventlist li.evsum:eq(+id+)).slideToggle();
                  });

          });

  But I'm getting nothing. Even when I replace the action (slideToggle) with
  an alert(id) I just get an alert saying This website says: and no id! I'm
  stumped!

  PLEASE, please please can someone help me out!

  Thanks in advance.
  Andy
  --
  View this message in 
  context:http://www.nabble.com/Passing-a-variable-to-a-function-tp19765153s272...
  Sent from the jQuery General Discussion mailing list archive at Nabble.com.


[jQuery] Re: Passing a variable to a function

2008-10-02 Thread andrewsquidge


Hi guys, this is the answer to how to pass a variable to a jquery function
and perform an action on a dynamic list.

http://www.learningjquery.com/2006/09/slicker-show-and-hide#comment-60792
http://www.learningjquery.com/2006/09/slicker-show-and-hide#comment-60792 



[EMAIL PROTECTED] wrote:
 
 
 HI,
 
 Thanks for your response, it's a good answer and works in the case you
 describe.
 
 Unfortunately I've got 2 more li's in between the clicked li and the
 toggled li. The full code looks like this:
 
 ul
 li class=evdatedate/li
 ll class=evname # name /li
 li class=evregionRegion/li
 li class=evlocLocation/li
 li class=evsumEvent summary to be hidden and displayed/li
 
 li class=evdatedate/li
 ll class=evname # name /li
 li class=evregionRegion/li
 li class=evlocLocation/li
 li class=evsumEvent summary to be hidden and displayed/li
 
 /ul
 
 Is there a way to say toggle next+2?
 
 Andy
 
 On Oct 1, 7:45 pm, MorningZ [EMAIL PROTECTED] wrote:
 So, and if am understanding correctly...  you have this html an are
 after some sort of accordion like behavior

 ul

     li class=evnameEvent 1 Name/li
     li class=evsumSummary of Event 1/li

     li class=evnameEvent 2 Name/li
     li class=evsumSummary of Event 2/li

     li class=evnameEvent 3 Name/li
     li class=evsumSummary of Event 3/li

     li class=evnameEvent 4 Name/li
     li class=evsumSummary of Event 4/li

     etc etc..
 /ul

 and you have evsum hidden by say:

 .evsum { display: none; }

 and you want to click on the evname and show the related evsum

 if thats the case, the jQuery could be like:

 $(document).ready(function() {
      $(.evname).click(function() {
           $(this).next().toggle();
      });

 });

 that would show (or hide, hence the use of toggle) the respective
 summary

 On Oct 1, 1:16 pm, andrewsquidge [EMAIL PROTECTED] wrote:

  Hi guys,

  I've been trying to get this literally all day! I just can't work it
 out.

  I've got this HTML:
  ul
  li class=evname 1 This is the event name /li
  li class=evsumsome text here/li
  /ul

  On click of li class=evname the li beneath should reveal. But
 because
  there are many of these ona page and they will be dynamic I need to set
 it
  to reveal only the relevant one.

  So my plan was to reveal the relevant li class=evsum in order.
 Here's
  the jquery:

          $(document).ready(function() {

                  $(li.evname).click(function() {
                          var id = this.id.replace('show_', );
                          $(#eventlist
 li.evsum:eq(+id+)).slideToggle();
                  });

          });

  But I'm getting nothing. Even when I replace the action (slideToggle)
 with
  an alert(id) I just get an alert saying This website says: and no id!
 I'm
  stumped!

  PLEASE, please please can someone help me out!

  Thanks in advance.
  Andy
  --
  View this message in
 context:http://www.nabble.com/Passing-a-variable-to-a-function-tp19765153s272...
  Sent from the jQuery General Discussion mailing list archive at
 Nabble.com.
 
 

-- 
View this message in context: 
http://www.nabble.com/Passing-a-variable-to-a-function-tp19765153s27240p19778198.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



[jQuery] Re: Passing a variable to a function

2008-10-01 Thread MorningZ

So, and if am understanding correctly...  you have this html an are
after some sort of accordion like behavior

ul

li class=evnameEvent 1 Name/li
li class=evsumSummary of Event 1/li

li class=evnameEvent 2 Name/li
li class=evsumSummary of Event 2/li

li class=evnameEvent 3 Name/li
li class=evsumSummary of Event 3/li

li class=evnameEvent 4 Name/li
li class=evsumSummary of Event 4/li

etc etc..
/ul

and you have evsum hidden by say:

.evsum { display: none; }

and you want to click on the evname and show the related evsum

if thats the case, the jQuery could be like:

$(document).ready(function() {
 $(.evname).click(function() {
  $(this).next().toggle();
 });
});


that would show (or hide, hence the use of toggle) the respective
summary





On Oct 1, 1:16 pm, andrewsquidge [EMAIL PROTECTED] wrote:
 Hi guys,

 I've been trying to get this literally all day! I just can't work it out.

 I've got this HTML:
 ul
 li class=evname 1 This is the event name /li
 li class=evsumsome text here/li
 /ul

 On click of li class=evname the li beneath should reveal. But because
 there are many of these ona page and they will be dynamic I need to set it
 to reveal only the relevant one.

 So my plan was to reveal the relevant li class=evsum in order. Here's
 the jquery:

         $(document).ready(function() {

                 $(li.evname).click(function() {
                         var id = this.id.replace('show_', );
                         $(#eventlist li.evsum:eq(+id+)).slideToggle();
                 });

         });

 But I'm getting nothing. Even when I replace the action (slideToggle) with
 an alert(id) I just get an alert saying This website says: and no id! I'm
 stumped!

 PLEASE, please please can someone help me out!

 Thanks in advance.
 Andy
 --
 View this message in 
 context:http://www.nabble.com/Passing-a-variable-to-a-function-tp19765153s272...
 Sent from the jQuery General Discussion mailing list archive at Nabble.com.


[jQuery] Re: Passing a variable to a function

2008-10-01 Thread amidude

I'm new to jquery as well. But I'm wondering if something like this
wouldn't work.

$(function() {

$(.evname a).click(function() {
$(this.hash).slideToggle(500);
return false;
});

});

You would, of course, have to add an anchor tag in your form. But that
would only help you with showing one. I'm using this as well and am
able to get my hidden to slide open. But since you want to go through
all of them I would there would need to be the need to retreive all of
the elements, determine which one is being clicked, then apply the
action to that particular click event.

On Oct 1, 12:16 pm, andrewsquidge [EMAIL PROTECTED] wrote:
 Hi guys,

 I've been trying to get this literally all day! I just can't work it out.

 I've got this HTML:
 ul
 li class=evname 1 This is the event name /li
 li class=evsumsome text here/li
 /ul

 On click of li class=evname the li beneath should reveal. But because
 there are many of these ona page and they will be dynamic I need to set it
 to reveal only the relevant one.

 So my plan was to reveal the relevant li class=evsum in order. Here's
 the jquery:

         $(document).ready(function() {

                 $(li.evname).click(function() {
                         var id = this.id.replace('show_', );
                         $(#eventlist li.evsum:eq(+id+)).slideToggle();
                 });

         });

 But I'm getting nothing. Even when I replace the action (slideToggle) with
 an alert(id) I just get an alert saying This website says: and no id! I'm
 stumped!

 PLEASE, please please can someone help me out!

 Thanks in advance.
 Andy
 --
 View this message in 
 context:http://www.nabble.com/Passing-a-variable-to-a-function-tp19765153s272...
 Sent from the jQuery General Discussion mailing list archive at Nabble.com.


[jQuery] Re: Passing a variable to a function

2008-10-01 Thread Steve Schnable
How can I subscribe it?

Steve


[jQuery] Re: Passing values to functions

2008-09-18 Thread ricardobeat

Easy way:

a href={$entry.cID} class=delete

$('.delete').click(function(){
   deleteid(this.href);
});


On Sep 18, 3:56 pm, Barney [EMAIL PROTECTED] wrote:
 Hi,

 I am trying to get my head around jquery and am converting some
 standard javascript code over.
 My old code was setup like this:
 function deleteid(id){
  // Delete by id

 }

 Then for html I have:
 a href=javascript:void(0); id=delete
 onClick=deleteid('{$entry.cID}')

 Now moving to jQuery I just can't figure out how to pass the id I want
 deleted attached to the click function.

 For example:
 $(#delete).click(function()
         {

         });

 How to I pass the id of that row I want deleted? I know this is
 probably something simple that I am just not getting my head around. :
 (


[jQuery] Re: Passing around sibling nodes in jQuery?

2008-08-21 Thread Ariel Flesler

This is doable:

var $both = $('dtterm/dtdddefn/dd');
$both.appendTo('#foo');

--
Ariel Flesler
http://flesler.blogspot.com/

On Aug 21, 11:52 am, Keith Hughitt [EMAIL PROTECTED] wrote:
 Hi all,

 I was wondering if anyone knows how I might be able to pass around two
 sibling nodes constructed on the fly? I'm building a definition list,
 and have a function which creates two adjacent domnodes, something
 like:

 var term = $('dtterm/dt');
 var defn = $('dddefn/dd');

 I was hoping to return them to be inserted into the list:

 return term.after(defn);

 However only one of the nodes gets returned. I could wrap them in a
 single container, return that container, and then take them back out,
 but that is somewhat roundabout.

 Any ideas?

 Thanks,
 Keith


[jQuery] Re: passing parameters to new Function as array... possible?

2008-07-19 Thread Ariel Flesler

I think your confusing something.

If you want to call a function with certain arguments from an array
you do:

var args = [ 1, 2, 3 ];
var sum = function( a, b, c ) { return a + b + c; };
sum.apply(this, args); // -- 6

If you want to create a function and specify the named arguments with
an array, then you do:

var args = [ 1, 2, 3 ];
var fnArgs = [ 'a', 'b', 'c' ];
fnArgs.push('return a+b+c;'); // the content
var sum = Function.apply(Function, fnArgs); // function(a,b,c){return a
+b+c;}
sum.apply(this, args); // -- 6

Cheers

--
Ariel Flesler
http://flesler.blogspot.com/

On 17 jul, 15:01, jquertil [EMAIL PROTECTED] wrote:
 its really a javascript question...

 The 3 parameters var1, var2, var3 that are used my my new Function -
 I'd like to be able to do this using an array. After an hour on the
 web I haven't been able to find a way...

                 var fn = new Function( 'var1','var2','var3', func);
                 fn( var1, var2, var3);

 in my imagination I had hoped to do something like this:

                 var my_array = new Array('var1','var2','var3');
                 var fn = new Function(my_array , func);
                 fn( my_array);


[jQuery] Re: Passing a variable into the $('selector') function

2008-07-03 Thread Stompfrog

msg was actually myDiv and in the end i got it to work with..

$('#'+msg)

Thanks very much for your helpful reply.

Cheers

On Jul 2, 11:16 pm, Erik Beeson [EMAIL PROTECTED] wrote:
 If msg is '#myDiv' and you have element with id=myDiv, then $(msg) will
 select it.

 If you think that's what you're doing and it isn't working for you, either
 your id is wrong or msg doesn't hold what you think (maybe it has a trailing
 \n?).

 --Erik

 On 7/2/08, Stompfrog [EMAIL PROTECTED] wrote:



  Hi all,

  I have a problem that I can't crack.

  I have a function similar to this..

$.ajax({
 type: POST,
 url: some.php,
 data: name=Johnlocation=Boston,
 success: function(msg){
   alert( Data Saved:  + msg );
 }
});

  The data that gets passed back to the function from some.php is a
  string which is the id of the div that I want to manipulate in the
  callback function e.g. #myDiv.

  My question is how can I get that div from the callback function using
  the msg variable because $(msg); doesn't work and neither does $
  ('+msg+');

  Thanks in advance,

  Stompfrog


[jQuery] Re: Passing a variable into the $('selector') function

2008-07-02 Thread Erik Beeson
If msg is '#myDiv' and you have element with id=myDiv, then $(msg) will
select it.

If you think that's what you're doing and it isn't working for you, either
your id is wrong or msg doesn't hold what you think (maybe it has a trailing
\n?).

--Erik


On 7/2/08, Stompfrog [EMAIL PROTECTED] wrote:


 Hi all,

 I have a problem that I can't crack.

 I have a function similar to this..

   $.ajax({
type: POST,
url: some.php,
data: name=Johnlocation=Boston,
success: function(msg){
  alert( Data Saved:  + msg );
}
   });

 The data that gets passed back to the function from some.php is a
 string which is the id of the div that I want to manipulate in the
 callback function e.g. #myDiv.

 My question is how can I get that div from the callback function using
 the msg variable because $(msg); doesn't work and neither does $
 ('+msg+');

 Thanks in advance,


 Stompfrog








[jQuery] Re: Passing scope to a nested anonymous function

2008-06-19 Thread Henry

On Jun 19, 4:04 am, Ariel Flesler wrote:
 On 18 jun, 17:45, meppum wrote:
 }).call(this.foo2); --- }).call(this);

While that answer would be superficially effective (in the sense of
resulting in code that would behave as specified) it is a stupidly
inefficient approach, and so not something that should be suggested as
a correction to the original code.

You have proposed changing the - foo2Function - to:-

function foo2Function() {
(function() {
this.foo = hi back;
}).call(this);
}

- but if the - this - that is the argument to the call method resolves
as a reference to the correct object then the whole thing can be
replaced with the considerably simpler and more efferent:-

function foo2Function() {
 this.foo = hi back;
}

More efficient, because it avoids the creation of a function object
each time the - foo2Function - is called, along with the call to -
call -.

snip
 script type=text/javascript
 function myFunction() {
 this.foo = hi;
 this.foo2 = foo2Function;

If a function is going to be used as a constructor (with the - new -
keyword) then assigning constant values to properties of the this
object within the constructors is less efficient and more unnatural
(in javascript terms) than assigning those values to the object
referred to by the function objects - prototype - property.

 }

 function foo2Function() {
 (function() {
 this.foo = hi back;
 }).call(this.foo2);
 }

So the above would be better as:-

function myFunction(){
}
myFunction.prototype.foo = hi;
myFunction.prototype.foo2 = function(){
this.foo = hi back;
};

 function test() {
 var obj = new myFunction();

 alert(obj.foo);

 obj.foo2();

 alert(obj.foo);
 }
 /script


[jQuery] Re: Passing scope to a nested anonymous function

2008-06-19 Thread Ariel Flesler

He is probably showing a dummy example to represent a more complex,
real situation.
So there's no sense in judging the exact code he posted.

That was the solution to his problem, that he should be able to adapt.

If you want to suggest a whole new approach to, what you suppose, he
needs.. then propose it directly to him, not by judging my fix.

Cheers

--
Ariel Flesler
http://flesler.blogspot.com


Henry ha escrito:
 On Jun 19, 4:04 am, Ariel Flesler wrote:
  On 18 jun, 17:45, meppum wrote:
  }).call(this.foo2); --- }).call(this);

 While that answer would be superficially effective (in the sense of
 resulting in code that would behave as specified) it is a stupidly
 inefficient approach, and so not something that should be suggested as
 a correction to the original code.

 You have proposed changing the - foo2Function - to:-

 function foo2Function() {
 (function() {
 this.foo = hi back;
 }).call(this);
 }

 - but if the - this - that is the argument to the call method resolves
 as a reference to the correct object then the whole thing can be
 replaced with the considerably simpler and more efferent:-

 function foo2Function() {
  this.foo = hi back;
 }

 More efficient, because it avoids the creation of a function object
 each time the - foo2Function - is called, along with the call to -
 call -.

 snip
  script type=text/javascript
  function myFunction() {
  this.foo = hi;
  this.foo2 = foo2Function;

 If a function is going to be used as a constructor (with the - new -
 keyword) then assigning constant values to properties of the this
 object within the constructors is less efficient and more unnatural
 (in javascript terms) than assigning those values to the object
 referred to by the function objects - prototype - property.

  }
 
  function foo2Function() {
  (function() {
  this.foo = hi back;
  }).call(this.foo2);
  }

 So the above would be better as:-

 function myFunction(){
 }
 myFunction.prototype.foo = hi;
 myFunction.prototype.foo2 = function(){
 this.foo = hi back;
 };

  function test() {
  var obj = new myFunction();
 
  alert(obj.foo);
 
  obj.foo2();
 
  alert(obj.foo);
  }
  /script


[jQuery] Re: Passing scope to a nested anonymous function

2008-06-19 Thread Michael Geary

Guys, you're both right.

We don't actually know what meppum's exact requirement is. Does the code
really have to strictly follow that exact design pattern? Or would it be
possible to use a simpler, more idiomatic approach to achieve the same
goals?

Either way, it doesn't hurt to get the original code working, so Ariel's
patch is just what's needed there.

But Henry, I did have a similar reaction to the code as you: Sure, you can
get this to work, but is it really necessary? There are much simpler ways to
do the same thing.

Meppum, can you clarify what the real requirements are, so we will all be a
little less confused? :-)

Thanks,

-Mike

 From: Ariel Flesler
 
 He is probably showing a dummy example to represent a more 
 complex, real situation.
 So there's no sense in judging the exact code he posted.
 
 That was the solution to his problem, that he should be able to adapt.
 
 If you want to suggest a whole new approach to, what you 
 suppose, he needs.. then propose it directly to him, not by 
 judging my fix.

  From: Henry
 
  While that answer would be superficially effective (in the sense of 
  resulting in code that would behave as specified) it is a stupidly 
  inefficient approach, and so not something that should be 
  suggested as a correction to the original code.
 
  ...
 
  So the above would be better as:-
 
  function myFunction(){
  }
  myFunction.prototype.foo = hi;
  myFunction.prototype.foo2 = function(){
  this.foo = hi back;
  };



[jQuery] Re: Passing scope to a nested anonymous function

2008-06-18 Thread Ariel Flesler

}).call(this.foo2); --- }).call(this);

--
Ariel Flesler
http://flesler.blogspot.com/

On 18 jun, 17:45, meppum [EMAIL PROTECTED] wrote:
 I have the below code and I'd like the alerts to say hi then hi
 there but it looks like I'm losing scope inside the anonymous
 function. This is a simplified version of a more complicated function
 I am trying to implement. I'm not sure if jquery can help with this,
 and I'm fine using vanilla JS code, but I've read the scoping
 tutorials and can't figure it out...

 html
     head
         script type=text/javascript
                 function myFunction() {
                     this.foo = hi;
                     this.foo2 = foo2Function;
                 }

                 function foo2Function() {
                     (function() {
                         this.foo = hi back;
                     }).call(this.foo2);
                 }

                 function test() {
                     var obj = new myFunction();

                     alert(obj.foo);

                     obj.foo2();

                     alert(obj.foo);
                 }
         /script
     /head
     body onload=test()

     /body
 /html


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Klaus Hartl

That seems to be a glitch due to the falsyness of 0. Try passing in a
string in the first place, this is what html expects anyway.

$('#foo').html('0');

--Klaus


On 17 Jun., 02:02, Lowell [EMAIL PROTECTED] wrote:
 When I call html(5) it will set the innerHtml of my element(s) to 5.
 However, zero seems to work differently. When I call html(0), it
 removes the contents of my element(s) and does not append anything. I
 had hoped after a call to html(0), that html() would return 0.

 Is this the expected behavior, or is this a bug?

 Thanks,
 Lowell


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Iair Salem

I would take it as undesired behaviour. but the reason is obvious.
So, if the .html(number) is variable, you could workaround it by
forcing it to eval as string: .html( + number)
I'm not sure, but it seems to be ok.
Iair.

On 16 jun, 21:02, Lowell [EMAIL PROTECTED] wrote:
 When I call html(5) it will set the innerHtml of my element(s) to 5.
 However, zero seems to work differently. When I call html(0), it
 removes the contents of my element(s) and does not append anything. I
 had hoped after a call to html(0), that html() would return 0.

 Is this the expected behavior, or is this a bug?

 Thanks,
 Lowell


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Morgan Allen
This has to do with the way JS evaluates true and false with 0. !0 == true.
The simple fix is passing String(0), line 964 (in current svn) is the
problem, if(!elem) return, change that to if(!elem  elem !== 0) return. I
will check for a bug report and submit a patch.

On Mon, Jun 16, 2008 at 5:02 PM, Lowell [EMAIL PROTECTED] wrote:


 When I call html(5) it will set the innerHtml of my element(s) to 5.
 However, zero seems to work differently. When I call html(0), it
 removes the contents of my element(s) and does not append anything. I
 had hoped after a call to html(0), that html() would return 0.

 Is this the expected behavior, or is this a bug?

 Thanks,
 Lowell




-- 
http://morglog.alleycatracing.com
Lets make up more accronyms!

http://www.alleycatracing.com
LTABOTIIOFR! ROFL! ROFL! ROFL!
Upcoming alley cats, reviews, touring logs, and a general congregation of
bike nerdity.


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Morgan Allen
I have noticed another really strange bug(?) here, numbers with a leading
zero come out wrong. like 0123 ends up as 83. Stranger yet, 18 is 18, 19 is
19 but 20 is 16? But it does not appear to be jQuery.

On Mon, Jun 16, 2008 at 8:57 PM, Morgan Allen [EMAIL PROTECTED]
wrote:

 This has to do with the way JS evaluates true and false with 0. !0 == true.
 The simple fix is passing String(0), line 964 (in current svn) is the
 problem, if(!elem) return, change that to if(!elem  elem !== 0) return. I
 will check for a bug report and submit a patch.


 On Mon, Jun 16, 2008 at 5:02 PM, Lowell [EMAIL PROTECTED] wrote:


 When I call html(5) it will set the innerHtml of my element(s) to 5.
 However, zero seems to work differently. When I call html(0), it
 removes the contents of my element(s) and does not append anything. I
 had hoped after a call to html(0), that html() would return 0.

 Is this the expected behavior, or is this a bug?

 Thanks,
 Lowell




 --
 http://morglog.alleycatracing.com
 Lets make up more accronyms!

 http://www.alleycatracing.com
 LTABOTIIOFR! ROFL! ROFL! ROFL!
 Upcoming alley cats, reviews, touring logs, and a general congregation of
 bike nerdity.




-- 
http://morglog.alleycatracing.com
Lets make up more accronyms!

http://www.alleycatracing.com
LTABOTIIOFR! ROFL! ROFL! ROFL!
Upcoming alley cats, reviews, touring logs, and a general congregation of
bike nerdity.


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Ariel Flesler

 I have noticed another really strange bug(?) here, numbers with a leading
 zero come out wrong. like 0123 ends up as 83. Stranger yet, 18 is 18, 19 is
 19 but 20 is 16? But it does not appear to be jQuery.

Leading zeros indicate the JS Interpreter that the number is octal,
that is, base 8.
Same as 0x for hexadecimal, base 16.
Use strings instead, '0123' won't cause any problems. If you have the
number in a var, just cast it like this:

my_num += '';

Cheers
--
Ariel Flesler
http://flesler.blogspot.com


[jQuery] Re: passing 0 to html() doesn't work like it does for other numbers

2008-06-17 Thread Ariel Flesler

Fixed http://dev.jquery.com/ticket/3053

Thanks
--
Ariel Flesler
http://flesler.blogspot.com/

On 17 jun, 00:57, Morgan Allen [EMAIL PROTECTED] wrote:
 This has to do with the way JS evaluates true and false with 0. !0 == true.
 The simple fix is passing String(0), line 964 (in current svn) is the
 problem, if(!elem) return, change that to if(!elem  elem !== 0) return. I
 will check for a bug report and submit a patch.

 On Mon, Jun 16, 2008 at 5:02 PM, Lowell [EMAIL PROTECTED] wrote:

  When I call html(5) it will set the innerHtml of my element(s) to 5.
  However, zero seems to work differently. When I call html(0), it
  removes the contents of my element(s) and does not append anything. I
  had hoped after a call to html(0), that html() would return 0.

  Is this the expected behavior, or is this a bug?

  Thanks,
  Lowell

 --http://morglog.alleycatracing.com
 Lets make up more accronyms!

 http://www.alleycatracing.com
 LTABOTIIOFR! ROFL! ROFL! ROFL!
 Upcoming alley cats, reviews, touring logs, and a general congregation of
 bike nerdity.


[jQuery] Re: Passing this to a function

2008-05-09 Thread markus.staab

you can do it, but this is a usual dom object, not a jquery
instance... simple pass the object to through Jquery like ref =
JQuery(ref);

On 9 Mai, 15:32, mac.gill [EMAIL PROTECTED] wrote:
 Can i pass 'this' to a custom function from an event handler
 eg.

 $('p').('click',function() {

   myCustomEvent(this);

 });

 myCustomEvent(ref) {

 //ref Object or JQuery object ?

   $.get(path_to_cgi,{name = ref.text()},function(data)
 { alert(Data :  + data});

 }


[jQuery] Re: Passing parameters to callback functions

2008-04-17 Thread Gauthier Segay

in your exemple, you can simply remove the parameter since the
function is declared as a closure that capture your var $id.

In most cases, callback function doesn't have any parameter, unless
explicitely specified in the documentation.

If you need to pre-bind parameters to your callback function, you need
to use currying technique of your choice.

see http://ejohn.org/blog/partial-functions-in-javascript/ as an
exemple to do so.

Hope this helps

On 15 avr, 23:09, Donald J Organ IV [EMAIL PROTECTED] wrote:
 Please ignore the fact that the single quotes are being escaped.

 Thanks

 Donald wrote:
  Is i possible to pass arguments to callback functions right now I
  have:

  $(.imagethumb).each(function() {
  $(this).bind( \'click\', function() {
  var $id = $(this)[0].id;
  $(#prodimage).fadeOut(slow,
  function($id) {
  $(#prodimage)[0].src = $(# + id ).attr( \'fullsize
  \' );
  $(#prodimage).fadeIn(slow);
  });
  }
  );
  });

  When it gets to the callback function for fadeOut $id is null.  How do
  I fix this??


[jQuery] Re: Passing parameters to callback functions

2008-04-16 Thread Richard D. Worth
There's no need to pass it. Since var $id and your callback are in the same
function-scope, a closure provides access. Here's a simpler example to
illustrate:

$(document).ready(function() {
  var i = 3;
  $(div).click(function() {
alert(i); // i and div.click fn are in the same function scope -
document.ready
  });
});

- Richard

Richard D. Worth
http://rdworth.org/

On Tue, Apr 15, 2008 at 5:07 PM, Donald [EMAIL PROTECTED] wrote:


 Is i possible to pass arguments to callback functions right now I
 have:

 $(.imagethumb).each(function() {
$(this).bind( \'click\', function() {
var $id = $(this)[0].id;
$(#prodimage).fadeOut(slow,
function($id) {
$(#prodimage)[0].src = $(# + id ).attr( \'fullsize
 \' );
$(#prodimage).fadeIn(slow);
});
}
);
 });

 When it gets to the callback function for fadeOut $id is null.  How do
 I fix this??



[jQuery] Re: Passing parameters to callback functions

2008-04-15 Thread Donald J Organ IV

Please ignore the fact that the single quotes are being escaped.

Thanks

Donald wrote:
 Is i possible to pass arguments to callback functions right now I
 have:

 $(.imagethumb).each(function() {
 $(this).bind( \'click\', function() {
 var $id = $(this)[0].id;
 $(#prodimage).fadeOut(slow,
 function($id) {
 $(#prodimage)[0].src = $(# + id ).attr( \'fullsize
 \' );
 $(#prodimage).fadeIn(slow);
 });
 }
 );
 });

 When it gets to the callback function for fadeOut $id is null.  How do
 I fix this??
   


[jQuery] Re: Passing variables between two function

2008-04-13 Thread Decagrog

Sorry for double post...
Thanks , simple and works! I've almost no knowledge of javascrpit but
jquery is very powerful and intuitive...i'm trying to make a sort of
horizontal menu with incorporated a slide for navigate to left and
right...it's essentially a trivial thing but if i can make something
userful  i'd like to share here.

On 11 Apr, 14:18, Richard D. Worth [EMAIL PROTECTED] wrote:
 Declare the variable in the same scope as each of those functions is
 declared. For example:

 $(function() {

   var pointX;

   $(.nav_slider).mousemove(function(e) { ... // set pointX here ... });

   $(document).scroll(function() { ...// use pointX here... });

 });

 - Richard

 Richard D. Worthhttp://rdworth.org/

 On Fri, Apr 11, 2008 at 4:33 AM, Decagrog [EMAIL PROTECTED] wrote:

  Hi all,
  I've a newbie question about variable scope...essentially  i've two
  anonimous function and i need to retrieve a variable
  generated into first function and use it in the second one.

  Here the basic code to get an idea of what i'm  trying...

   var pointX ;
   $(.nav_slider).mousemove(function(e){
 pointX = e.pageX ;
 // do some other stuff with  pointX ...
   });

   $(document).scroll(function () {
   var docH = $(window).height();
   var   docW = $(window).width();
   docWcenter =  docW / 2;

  //here i need again pointX ...
  $(#point).css( 'position',
  'relative' ).animate({ left :docWcenter + pointX + px}, 200 );
   });

  How i can retrieve it?


[jQuery] Re: Passing variables between two functions

2008-04-13 Thread Decagrog

It give me an undefined variable...
For error i've make a double post with that question, here
http://groups.google.com/group/jquery-en/browse_thread/thread/85431413ea0aad30/2f47f4c6d1d175df?lnk=gstq=between+function#2f47f4c6d1d175df
a guy gave me a solution...

On 12 Apr, 19:21, J Moore [EMAIL PROTECTED] wrote:
 looks good. pointX is a global variable and can be accessed by both
 functions. What's the problem?

 On Apr 11, 6:13 am, Decagrog [EMAIL PROTECTED] wrote:

  Hi all,
  I've a newbie question about variable scope...essentially  i've two
  anonimous function and i need to retrieve a variable generated into
  first function and use it in the second one.

  Here the basic code to get an idea of what i'm  trying...

var pointX ;
$(.nav_slider).mousemove(function(e){
  pointX = e.pageX ;
  // do some other stuff with  pointX ...
});

$(document).scroll(function () {
var docH = $(window).height();
var   docW = $(window).width();
docWcenter =  docW / 2;

   //here i need again pointX ...
   $(#point).css( 'position',
  'relative' ).animate({ left :docWcenter + pointX + px}, 200 );
});


[jQuery] Re: Passing variables between two functions

2008-04-12 Thread J Moore


looks good. pointX is a global variable and can be accessed by both
functions. What's the problem?

On Apr 11, 6:13 am, Decagrog [EMAIL PROTECTED] wrote:
 Hi all,
 I've a newbie question about variable scope...essentially  i've two
 anonimous function and i need to retrieve a variable generated into
 first function and use it in the second one.

 Here the basic code to get an idea of what i'm  trying...

   var pointX ;
   $(.nav_slider).mousemove(function(e){
 pointX = e.pageX ;
 // do some other stuff with  pointX ...
   });

   $(document).scroll(function () {
   var docH = $(window).height();
   var   docW = $(window).width();
   docWcenter =  docW / 2;

  //here i need again pointX ...
  $(#point).css( 'position',
 'relative' ).animate({ left :docWcenter + pointX + px}, 200 );
   });


[jQuery] Re: Passing variables between two function

2008-04-11 Thread Richard D. Worth
Declare the variable in the same scope as each of those functions is
declared. For example:

$(function() {

  var pointX;

  $(.nav_slider).mousemove(function(e) { ... // set pointX here ... });

  $(document).scroll(function() { ...// use pointX here... });

});

- Richard

Richard D. Worth
http://rdworth.org/

On Fri, Apr 11, 2008 at 4:33 AM, Decagrog [EMAIL PROTECTED] wrote:


 Hi all,
 I've a newbie question about variable scope...essentially  i've two
 anonimous function and i need to retrieve a variable
 generated into first function and use it in the second one.

 Here the basic code to get an idea of what i'm  trying...

  var pointX ;
  $(.nav_slider).mousemove(function(e){
pointX = e.pageX ;
// do some other stuff with  pointX ...
  });


  $(document).scroll(function () {
  var docH = $(window).height();
  var   docW = $(window).width();
  docWcenter =  docW / 2;

 //here i need again pointX ...
 $(#point).css( 'position',
 'relative' ).animate({ left :docWcenter + pointX + px}, 200 );
  });

 How i can retrieve it?



[jQuery] Re: passing css to an ID via select/output

2008-03-10 Thread Richard D. Worth
Maybe you want:

$(#bodyCopy).css(font-family, $(this).val());

Also, you don't have a /select before your /form.

- Richard

Richard D. Worth
http://rdworth.org/

On Sun, Mar 9, 2008 at 10:27 PM, timfm [EMAIL PROTECTED] wrote:


 Hi All,

 I'm new here and to jQuery. Trying to get started by developing a
 typographic tools for visual designers learning CSS. I want to pass
 the value of option as font-family to a div. Here's what I have so
 far:

 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd;
 html xmlns=http://www.w3.org/1999/xhtml; xml:lang=en
 head
 title/title
 meta http-equiv=Content-Type content=text/html; charset=utf-8 /
 script type=text/javascript src=/js/jquery-1.2.3.js/script
 script language=JavaScript type=text/javascript
 !--

 $(#fontSelect).change(function () {
switch ($(this).val())
$(#bodyCopy).css(font-family);
 }

 // --
 /script
 /head

 body
 div id=bodyCopy
  pThe darkness of the type as set in mass, which is not the
 same as the emweight/em of the face itself. The spacing of words
 and letters, the leading of lines, and the incidence of capitals, not
 to mention the color (i.e., darkness) of the ink and of the paper it
 is printed on, all affect the color of the type./p
 /div

 form
select id=fontSelect
option value=courier newCourier/option
option value=georgiaGeorgia/option
option value=verdanaVerdana/option
 /form
 /body
 /html

 Also, strangely, if I move the #bodyCopy div below the form it
 doesn't render



[jQuery] Re: passing form data to $.ajax

2008-03-05 Thread andrea varnier

On 4 Mar, 12:58, Mike Alsup [EMAIL PROTECTED] wrote:
 You cannot upload files with ajax.  Use the form plugin for that 
 functionality.

thank you :)


[jQuery] Re: passing form data to $.ajax

2008-03-04 Thread Mike Alsup

You cannot upload files with ajax.  Use the form plugin for that functionality.


  I'm wondering is there a way to pass form data to $.ajax()?
  let's say I want to upload a file, what is the correct way?
  passing the content of the input type=file this way
  $('#myInput').val()
  doesn't work.
  How is that done?
  thank you
  andrea



  1   2   >