[jQuery] Re: Working with identical objects

2009-02-15 Thread Tze Yang Ng

According to the jquery doc, $('option:selected',
ModulesListObj).val() returns the content of the value attribute of
the first matched element.

U may wish to try something like the following to get the desired array:

$('something', ModulesListObj).map(function(){
  return $(this).val();
});

TY

==

On Mon, Feb 16, 2009 at 10:33 AM, ShurikAg  wrote:
>
> Actually this:
> alert(jQ("option:selected", ModulesListObj).val())
>
> works perfectly right, if there is only one select object on the page.
> If there are two or more it always picks up the first one.
>
> On Feb 15, 1:04 pm, Ricardo Tomasi  wrote:
>> That's quite a lot of code to read through in an email. Try reducing
>> your code to the least necessary to exemplify your problem, then
>> someone might take the time to help.
>>
>> From what I see:
>> alert(jQ("option:selected", ModulesListObj).val())
>>
>> This is catching all the selected options inside ModulesListObj, and
>> that will be one option for every select you added. val() will then
>> return the value only for the first element in that collection. That
>> should probably be:
>>
>> alert(jQ("option:selected", this).val())
>>
>> cheers,
>> - ricardo
>>
>> On Feb 12, 11:53 pm, ShurikAg  wrote:
>>
>> > I don't believe that nobody have any suggestion...



-- 
http://ngty77.blogspot.com


[jQuery] Re: Working with identical objects

2009-02-15 Thread ShurikAg

Actually this:
alert(jQ("option:selected", ModulesListObj).val())

works perfectly right, if there is only one select object on the page.
If there are two or more it always picks up the first one.

On Feb 15, 1:04 pm, Ricardo Tomasi  wrote:
> That's quite a lot of code to read through in an email. Try reducing
> your code to the least necessary to exemplify your problem, then
> someone might take the time to help.
>
> From what I see:
> alert(jQ("option:selected", ModulesListObj).val())
>
> This is catching all the selected options inside ModulesListObj, and
> that will be one option for every select you added. val() will then
> return the value only for the first element in that collection. That
> should probably be:
>
> alert(jQ("option:selected", this).val())
>
> cheers,
> - ricardo
>
> On Feb 12, 11:53 pm, ShurikAg  wrote:
>
> > I don't believe that nobody have any suggestion...


[jQuery] Re: Working with identical objects

2009-02-15 Thread Ricardo Tomasi

Sorry for the double messages. Actually that could simply be:

alert( jQ(this).val() )

as val() called on a  will return the selected option's value.

On Feb 15, 6:04 pm, Ricardo Tomasi  wrote:
> That's quite a lot of code to read through in an email. Try reducing
> your code to the least necessary to exemplify your problem, then
> someone might take the time to help.
>
> From what I see:
> alert(jQ("option:selected", ModulesListObj).val())
>
> This is catching all the selected options inside ModulesListObj, and
> that will be one option for every select you added. val() will then
> return the value only for the first element in that collection. That
> should probably be:
>
> alert(jQ("option:selected", this).val())
>
> cheers,
> - ricardo
>
> On Feb 12, 11:53 pm, ShurikAg  wrote:
>
> > I don't believe that nobody have any suggestion...


[jQuery] Re: Working with identical objects

2009-02-15 Thread Ricardo Tomasi

That's quite a lot of code to read through in an email. Try reducing
your code to the least necessary to exemplify your problem, then
someone might take the time to help.

>From what I see:
alert(jQ("option:selected", ModulesListObj).val())

This is catching all the selected options inside ModulesListObj, and
that will be one option for every select you added. val() will then
return the value only for the first element in that collection. That
should probably be:

alert(jQ("option:selected", this).val())

cheers,
- ricardo

On Feb 12, 11:53 pm, ShurikAg  wrote:
> I don't believe that nobody have any suggestion...


[jQuery] Re: Working with identical objects

2009-02-12 Thread ShurikAg

I don't believe that nobody have any suggestion...


[jQuery] Re: Working with identical objects

2009-02-12 Thread ShurikAg

Here is my code:

/**
 * Page template part setup div
 */
(function(jQ){
/**
 * form state
 */
var STATE = "new";
/**
 * Request URL
 */
var RequestUrl = rootUrl+"/aranAjx.php?mod=pages";
/**
 * indicator if there is one form is open
 */
var formOpen = false;
/**
 * Actions
 */
var MODULE_LIST = "act=modules";
/**
 * Load image object
 */
var loadImgObj = jQ("").attr("id", "stdLoadImg").attr
("src", jQ.STD_LOAD_IMG);
/**
 * Object of template part form
 */
var PartObj = null;
/**
 * HTML select object of availble options
 */
var ModulesListObj = null;

/**
 * Events
 */
var OnBeforeSend = function(){
jQ(this).append(loadImgObj);
};
var OnSuccess = function(data){
//parse the data
if(data['status'] == "OK"){
ShowFormMessage(data['body']['message']);
//change tha action to edit
jQ("#action").val("edit");
jQ("#tplName").attr("readonly", "readonly");
} else if(data['status'] == "FAIL"){
ShowFormError(data['reason']);
}
};
var OnSuccessGetMosules = function(data){
//parse the data
if(data['status'] == "OK"){
var modules = data['body']['modules'];
ModulesListObj = 
jQ("").change(OnModuleSelect);
jQ.each(modules, function(i, module){
jQ("").attr("value", 
module.modeCode).text
(module.name).appendTo(ModulesListObj);
});
ModulesListObj.insertBefore(loadImgObj);
} else if(data['status'] == "FAIL"){
ShowFormError(data['reason']);
}
};
var OnError = function(txt){
ShowFormError("Fatal error during request: "+txt);
};
var OnComplete = function(){
jQ(loadImgObj, this).remove();
};
/**
 * init part
 */
jQ.fn.PartInit = function(){
if(formOpen){
return;
}
if(!jQ(this).is("div")){
$.log("Template part form must be 'DIV' element!");
}
PartObj = this;
if(STATE == "edit"){

} else if (STATE == "new"){
//send the reauest for module list first.
var options = {
url: RequestUrl,
data: MODULE_LIST
};
//bind events
this.onBeforeSend = OnBeforeSend;
this.onError = OnError;
this.onComplete = OnComplete;
this.onSuccess = OnSuccessGetMosules;

//send ajax request
jQ(this).ijajax(options, this);
return jQ(this);
}

}
/**
 * Module selection event handler
 */
var OnModuleSelect = function(){
alert(jQ("option:selected", ModulesListObj).val());
};
/**
 * Show form error
 */
var ShowFormError = function(err){
jQ("").addClass("araneumErrDiv").text(err).prependTo
("#tplPartsContainer");
};

/**
 * Show form message
 */
var ShowFormMessage = function(mess){

jQ("").addClass("araneumMessDiv").text(mess).prependTo
("#tplPartsContainer");
};
/**
 * remove error and message divs
 */
var RemoveErrorMessage = function(){
jQ(".araneumMessDiv,.araneumErrDiv").remove();
};
})(jQuery)