Page 3 of 3 FirstFirst 123
Results 21 to 30 of 30
  1. #21

    Default Re: Hack: Display a text in Select that is not Found in options.


    Quote Originally Posted by kamahak View Post
    In this case, the hack is to make html 'select' element show different text when you choose an option. In the example, it was supposed to show Volvo or Harley. Instead, when you select it, it shows: Cars, Volvo or Motorcycles, Harley.
    This statement is not yet posted when i replied to the TS...you're just late..

  2. #22

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by kamahak View Post
    Hello again. finally remembered to fix this.

    Yeah, I know it would be easier to use the focus() event. But, IMHO, the beauty of jQuery is to be able to shorten JavaScript code as much as possible. As they're infamous mantra goes, "write less, do more".

    Anyways, on second look of my code. The problem was obviously that my code was not remembering the last category when switching between the two. Thus, creating a bug. So, I made the appropriate fixes.

    Code:
    $("select").change(function () {
        var oldc;
        return function (event) {
            var foo = $("select option:selected"),
                bar = foo.text(),
                cat = foo.parent().attr("label");
            if (oldc) { // This won't exist the first time we run this
                oldfoo = $("select option:contains('" + oldc + ":')");
                oldHTML = oldfoo.html();
                oldHTML && oldfoo.html(oldHTML.replace(oldc + ': ', ''));
            }
            foo.text(cat + ': ' + bar);
            oldc = cat; // Remember it for next time
        };
    }());
    JSFiddle Linkage

    By this time, I was having so much fun, I was just staring blankly at the screen when; BAM!

    Epiphany.

    The profound solution was not to search for or save the last category but to use other special characters found on the list. That's right the colon.

    The result, a beautiful jQuery four-liner.

    Code:
    $("select").change(function (event) {
        var foo = $("select option:selected"),
            bar = foo.text(),
            cat = foo.parent().attr("label"),
            old = $("select option:contains(':')"),
            oldb = old.html();
    
        oldb && old.html(oldb.replace(oldb.substr(0, oldb.indexOf(':') + 2),''));
        foo.text(cat + ': ' + bar);
    });
    JSFiddle Linkage

    Note: I say four-liner because this script is basically just four lines of code. Just edited for readability.

    Thank you TS for taking away the boring times.
    nice code dude.. chuy imo solution bai.. but if you don't mind i found something that's not in my original "specs" but i think you made this your own now.. hehe.. anyway.. the original HTML should be the original.. mao lng.. bow.. i have a TODO hack for you.. creating an event for an already selected list in select list.. lisud kau bro oi..

  3. #23

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by kamahak View Post
    .

    The result, a beautiful jQuery four-liner.
    i can obscure my code and make it 1 liner.. bwahahaha..

  4. #24

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by nullpointer View Post
    This statement is not yet posted when i replied to the TS...you're just late..
    Ha?

    First of all, Wala ko makig away.

    Second, nangutana ka unsay gipasabot ni TS sa hack sa iya sample. Gitubag ra tika, stating it's probably because of your understanding of what a hack is.

    Third, @TS- it's make code, end war. =P

    Fourth, ??

    Fifth, Profit!

  5. #25
    Elite Member noy.juan's Avatar
    Join Date
    Mar 2010
    Gender
    Male
    Posts
    1,521
    Blog Entries
    1

    Default Re: Hack: Display a text in Select that is not Found in options.

    js coding are like mind puzzle...

  6. #26

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by belthazar View Post
    nice code dude.. chuy imo solution bai.. but if you don't mind i found something that's not in my original "specs" but i think you made this your own now.. hehe.. anyway.. the original HTML should be the original.. mao lng.. bow.. i have a TODO hack for you.. creating an event for an already selected list in select list.. lisud kau bro oi..
    ty diay sa compliment. pero wa ko kasabot sa imo specs na wala sa imoha original. ako rmn tingai toh gi update ang inyo jsfiddle na...well, fiddle. hehe.

    HTML should still be the same.

    Also, sa imo pasabot na todo na hack ba. Like, kintahay selected na ang Volvo nya i-select balik kay mu trigger ug event?

  7. #27

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by noy.juan View Post
    js coding are like mind puzzle...
    HTML/JS + Python is like a pain in the ass..

  8. #28

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by kamahak View Post
    ty diay sa compliment. pero wa ko kasabot sa imo specs na wala sa imoha original. ako rmn tingai toh gi update ang inyo jsfiddle na...well, fiddle. hehe.

    HTML should still be the same.
    kuan bai, after ma change ang text sa option, dapat kung i click nimo ang dropdown, mubalik xa sa original kay kato imo is after na change, pag click nimo sa drop down kay ang text sa option kay kato nang changed text.. kuha ra? pero minor ra na oi..

    Quote Originally Posted by kamahak View Post
    Also, sa imo pasabot na todo na hack ba. Like, kintahay selected na ang Volvo nya i-select balik kay mu trigger ug event?

    Hmm..
    hands up ko ana bai.. kayasa lisud kau.. @_@

  9. #29

    Default Re: Hack: Display a text in Select that is not Found in options.

    dmana hack TS oi...its a simple trick ra...maybie newbie lang na xa sa programming...

  10. #30

    Default Re: Hack: Display a text in Select that is not Found in options.

    Quote Originally Posted by tearz777 View Post
    dmana hack TS oi...its a simple trick ra...maybie newbie lang na xa sa programming...
    dude.. what's with being so disagreeable?

    let me ask you na lang bai.. how do you define a hack?

  11.    Advertisement

Page 3 of 3 FirstFirst 123

Similar Threads

 
  1. Looking For: Lawyer that is an expert in annulment
    By Jason4eveR in forum Specialty Services
    Replies: 3
    Last Post: 06-21-2018, 01:28 PM
  2. Why Financial Education is not taught in school?
    By *dudes* in forum Campus Talk
    Replies: 39
    Last Post: 10-27-2010, 05:55 PM
  3. Looking For: Sony Ericsson K550i or k800i that is cheap and in perfect condition..
    By JeffCee in forum Cellphones & Accessories
    Replies: 13
    Last Post: 08-02-2009, 12:10 PM
  4. Why Financial Education is not taught in school?
    By *dudes* in forum Politics & Current Events
    Replies: 22
    Last Post: 11-23-2008, 03:10 PM
  5. Replies: 8
    Last Post: 01-14-2006, 10:13 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top