[jQuery] Re: Setting a newly inserted option as the selected option

2009-04-17 Thread Nando

Thanks Raja. That worked!

For reference, I also needed to put something in place to wait until
the .trigger('refreshOpts'); call had completed. The use of animate()
as a sort of sleep routine is a bit of a kludge, since it
seems .trigger() doesn't implement a callback,  so I wound up with
this:

$(#addRefForm).submit(function() {
var author = $(#author).val()
var detail = $(#detail).val()
var refYear = $(#refYear).val()
var refType = $(#refType option:selected).val()
var newReference = 1
$.post('index.cfm?view=saveReferenceFromPopup', {
author:author,
detail:detail,
refYear:refYear,
refType:refType,
newReference:newReference
},  function(data,status) {
// console.log(status)
if(status == 'success'){
 
$(#refSelectBox).trigger('refreshOpts');
 
$(#refSelectBox).animate({opacity: 1.0}, 950, function(){
$(#refSelectBox 
option:selected).removeAttr(selected);
$(#refSelectBox 
option[text^= + author + ]).attr
(selected,selected);
  });
  }
  }
);



On Apr 17, 2:40 pm, Raja Koduru kscr...@gmail.com wrote:
 $(#refSelectBox option[text^= + author + ]).attr(selected,selected);

 I guess the above is doable.
 let me know.

 - raja koduru

 On Thu, Apr 16, 2009 at 11:16 PM,Nandod.na...@gmail.com wrote:

  I'd like set a newly inserted option in a select box as the selected
  option. I'm trying to use jQuery to select the option using the option
  text, which begins with the author name as defined in the function.

  In the examples I've found, $(#refSelectBox option[text^=author])
  would presumably select any option that begins with the literal
  author, but I need it evaluated instead.

  Given the following ...

  $(#addRefForm).submit(function() {
                         var author = $(#author).val()
                         var detail = $(#detail).val()
                         var refYear = $(#refYear).val()
                         var refType = $(#refType option:selected).val()
                         var newReference = 1
                         $.post('index.cfm?view=saveReferenceFromPopup', {
                                 author:author,
                                 detail:detail,
                                 refYear:refYear,
                                 refType:refType,
                                 newReference:newReference
                                 },  function(data,status) {
                                         if(status == 'success'){
                                                  
  $(#refSelectBox).trigger('refreshOpts');
                                                  $(#refSelectBox 
  option[text^=author]).attr
  (selected,selected);
                                           }
                                   }
                         );

                         $('#dialog').dialog('close');
                         return false;
                 });

  ... how to select the newly inserted option in #refSelectBox using the
  text attribute and set it to the selected option?

  Any alternate suggestions are most welcome!

  Thanks,
 Nando


[jQuery] Setting a newly inserted option as the selected option

2009-04-16 Thread Nando

I'd like set a newly inserted option in a select box as the selected
option. I'm trying to use jQuery to select the option using the option
text, which begins with the author name as defined in the function.

In the examples I've found, $(#refSelectBox option[text^=author])
would presumably select any option that begins with the literal
author, but I need it evaluated instead.

Given the following ...

$(#addRefForm).submit(function() {
var author = $(#author).val()
var detail = $(#detail).val()
var refYear = $(#refYear).val()
var refType = $(#refType option:selected).val()
var newReference = 1
$.post('index.cfm?view=saveReferenceFromPopup', {
author:author,
detail:detail,
refYear:refYear,
refType:refType,
newReference:newReference
},  function(data,status) {
if(status == 'success'){
 
$(#refSelectBox).trigger('refreshOpts');
 $(#refSelectBox 
option[text^=author]).attr
(selected,selected);
  }
  }
);

$('#dialog').dialog('close');
return false;
});

... how to select the newly inserted option in #refSelectBox using the
text attribute and set it to the selected option?

Any alternate suggestions are most welcome!

Thanks,
Nando


[jQuery] Converting JSON to html output

2009-04-14 Thread Nando

Hi,

I'm a jQuery and Javascript noob, and can't seem to get this to work.
The JSON output looks right to me via console.log(result), but the
select box isn't being populated. The select box needs to be populated
onfocus, because the interface is set up to allow the user to add new
options to the select via a popup without a page refresh.

$(function() {

  $.getJSON('index.cfm?view=listReferenceJSON',
function(result,status) {
  console.log(result)
  var str = ''
  for(var i=0; i  result.ROWCOUNT; i++) {
str+= 'option value='+result.DATA.REFERENCEID[i]
+''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')option'
  }
$(refSelectBox).bind('focus', function(event, ui) {
  $(#refSelectBox).html(str)
}
});
});

select id=refSelectBox/select

Thanks in advance for any help.

Nando


[jQuery] Re: Converting JSON to html output

2009-04-14 Thread Nando

Sure. Here's the JSON string being returned by the server. The only
thing that will need some fiddling is that the year is being returned
as a float. Not sure how to get that displayed as just an integer in
JS.

{COLUMNS:
[REFERENCEID,AUTHOR,DETAIL,REFYEAR,REFTYPE],DATA:[[1,Chen
 Chen,Chinese Herbs and Recipes, Second Revision,2009.0,1],
[16,Dana Cat,,,1],[5,Simon Becker,Chinese Medicine Today,
2008.0,1],[14,tom cat,,2009.0,1],[4,Becker, Simon,Chinese
Medicine Today,2009.0,2],[3,Dana,Dana's Secret Pasta Recipe,
2008.0,5],[15,bob cat,,2007.0,5]]}

On Apr 14, 4:32 pm, MorningZ morni...@gmail.com wrote:
 Can you give an example of the JSON to help?

 On Apr 14, 9:24 am, Nando d.na...@gmail.com wrote:

  Hi,

  I'm a jQuery and Javascript noob, and can't seem to get this to work.
  The JSON output looks right to me via console.log(result), but the
  select box isn't being populated. The select box needs to be populated
  onfocus, because the interface is set up to allow the user to add new
  options to the select via a popup without a page refresh.

  $(function() {

    $.getJSON('index.cfm?view=listReferenceJSON',
      function(result,status) {
        console.log(result)
        var str = ''
        for(var i=0; i  result.ROWCOUNT; i++) {
          str+= 'option value='+result.DATA.REFERENCEID[i]
  +''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')option'
        }
          $(refSelectBox).bind('focus', function(event, ui) {
            $(#refSelectBox).html(str)
          }
      });

  });

  select id=refSelectBox/select

  Thanks in advance for any help.

  Nando


[jQuery] Re: Converting JSON to html output

2009-04-14 Thread Nando

I see I'm really still a complete klutz at javascript.

Thanks very much Stephan! I will give that a try.

On Apr 14, 5:56 pm, MorningZ morni...@gmail.com wrote:
 Well, just putting the JSON into a JSON viewer (this one is 
 excellent:http://www.codeplex.com/JsonViewer) you pasted into your last post

 you have no property of .ROWCOUNT, so that's a bad start..

 this is a quick mock up that works

 http://paste.pocoo.org/show/112508/

 (sorry about the if's... i never trust that the data is intact/
 complete)

 On Apr 14, 10:50 am, Nando d.na...@gmail.com wrote:

  Sure. Here's the JSON string being returned by the server. The only
  thing that will need some fiddling is that the year is being returned
  as a float. Not sure how to get that displayed as just an integer in
  JS.

  {COLUMNS:
  [REFERENCEID,AUTHOR,DETAIL,REFYEAR,REFTYPE],DATA:[[1,Chen
   Chen,Chinese Herbs and Recipes, Second Revision,2009.0,1],
  [16,Dana Cat,,,1],[5,Simon Becker,Chinese Medicine Today,
  2008.0,1],[14,tom cat,,2009.0,1],[4,Becker, Simon,Chinese
  Medicine Today,2009.0,2],[3,Dana,Dana's Secret Pasta Recipe,
  2008.0,5],[15,bob cat,,2007.0,5]]}

  On Apr 14, 4:32 pm, MorningZ morni...@gmail.com wrote:

   Can you give an example of the JSON to help?

   On Apr 14, 9:24 am, Nando d.na...@gmail.com wrote:

Hi,

I'm a jQuery and Javascript noob, and can't seem to get this to work.
The JSON output looks right to me via console.log(result), but the
select box isn't being populated. The select box needs to be populated
onfocus, because the interface is set up to allow the user to add new
options to the select via a popup without a page refresh.

$(function() {

  $.getJSON('index.cfm?view=listReferenceJSON',
    function(result,status) {
      console.log(result)
      var str = ''
      for(var i=0; i  result.ROWCOUNT; i++) {
        str+= 'option value='+result.DATA.REFERENCEID[i]
+''+result.DATA.AUTHOR[i]+' ('+result.DATA.REFYEAR[i]+')option'
      }
        $(refSelectBox).bind('focus', function(event, ui) {
          $(#refSelectBox).html(str)
        }
    });

});

select id=refSelectBox/select

Thanks in advance for any help.

Nando