How add title attribute in options?

166 views
Skip to first unread message

Frodogus

unread,
Apr 20, 2011, 6:24:12 AM4/20/11
to struts2-jquery
I use select of struts2-jquery like the example with a Map object.
jsp code:
<s:url id="d_url" action="DetailAction"/>
<sj:select
href="%{d_url}"
id="Subsistema"
key="Subsistema"
name="Subsistema"
list="languageMap"
cssClass="cajaReq"
emptyOption="true" />

I need the title of the option is equal to the value of each option.
Is it possible?
Message has been deleted

Frodogus

unread,
Apr 25, 2011, 7:57:02 AM4/25/11
to struts2-jquery
No way?

Frodogus

unread,
Apr 25, 2011, 11:03:32 AM4/25/11
to struts2-jquery
I tried add attribute with javascript but didn't work (it didn't show
values because of the select didn't have options):

$(document).ready(function() {
$("#Subsistema option").each(function(){
alert('opcion '+$(this).text()+' valor '+ $
(this).attr('value'))
});
});

jogep

unread,
Apr 26, 2011, 3:20:18 AM4/26/11
to struts2-jquery
You execute your javascript after document is ready.
Are you sure your selectbax is in this state already filled?

Try to do this in an onCompleteTopic.

Johannes
---
web: http://www.jgeppert.com
twitter: http://twitter.com/jogep
> });- Zitierten Text ausblenden -
>
> - Zitierten Text anzeigen -

Frodogus

unread,
Apr 26, 2011, 4:11:01 AM4/26/11
to struts2-jquery
Your reply is perfect!
I put the source code with the solution.
<sj:select
href="%{d_url}"
id="Subsistema"
key="Subsistema"
name="Subsistema"
list="languageMap"
cssClass="cajaReq"
emptyOption="true"
onCompleteTopics="complete" />

<script>
$.subscribe('complete', function(event,data) {
$("#Subsistema option").each(function(){
$(this).attr("title", $(this).attr('value'));
});
});
</script>

More thanks!.

Darshan Shroff

unread,
Apr 26, 2011, 5:34:02 AM4/26/11
to struts2...@googlegroups.com
You could also do below in a common.js file which would be included in all jsp's.
This way no need to write anything extra (oncompletetopics) for individual selectboxes :-

$(document).ready(function() {

$("select").each( function (){
        
    var sel = this;

    // setting tool tip of select box as selected value
    var index=sel.selectedIndex;
    if(sel.id!=""){
        $('#'+sel.id).attr('title',sel.options[index].text);
    }

    // setting tool tip for showing on hover
          for(i=0;i<sel.length;i++){  
              sel.options[i].title = sel.options[i].text;   
          }  
      }  
      ); 
 });

--
You received this message because you are subscribed to the Google Groups "struts2-jquery" group.
To post to this group, send email to struts2...@googlegroups.com.
To unsubscribe from this group, send email to struts2-jquer...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/struts2-jquery?hl=en.


Frodogus

unread,
Apr 27, 2011, 6:02:31 AM4/27/11
to struts2-jquery
Darshan's script not work. I think that don't exist select object when
document is ready.

Thanks anyways.
Reply all
Reply to author
Forward
0 new messages