Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Selecting from buttons

Posted on 2015-02-06
2
Medium Priority
?
51 Views
Last Modified: 2015-03-03
Hi,

------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I have the following code in my page:

<h3>Filter By</h3>

@for (int n = 1; n < 4; n++)
 {

<div class="control-group">
<div class="control-label">

 <div class="input-append">
    <select class="clause-selector gen-clauses">
            <option value="">@Translations.lang.select</option>
    </select>
        <button id="alpha-list" class="btn clause-list" type="button">
            <i class="icon-list"></i>
        </button>
        <button id="grouped-list" style="display:none" class="btn clause-list" type="button">
            <i class="icon-cat"></i>
        </button>
 </div>

</div>
</div>

}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------


the two buttons toggle using the following JQUERY code:

    $('.clause-list').on("click", function (event) {
        var other = $(this).siblings('.clause-list').first();
        buildSearchClauses($(this).prevAll('.clause-selector').first(), (this.id !== 'alpha-list'));
        $(this).hide();
        other.show();
    });

------------------------------------------------------------------------------------------------------------------------------------------------------------------------


Now I want to write a JQUERY statement to get the Button selected by the user at the moment. Then I want to use it to do some action (Something like this):

function PerformActionOnButtonStatus()
{
     $('select.gen-clauses').each(function (key, sel)
    {    
     var selectedStatus = $(this).children('button').filter("button:selected").text();  //Can you help
     var sel = Selected Button object;  //Can you help
     
     if(selectedStatus = 'grouped')   //Grouped means that I selected button with id="alpha-list"
         { CallFunction1(sel, true); }
    else
         { CallFunction1(sel, false); }

    }
}    
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
0
Comment
Question by:Arikkan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 43

Accepted Solution

by:
David S. earned 2000 total points
ID: 40596230
Buttons don't have a selected state on their own. You'll need to set a property on them (or add a class to them) within your JS code when one is clicked (and change the value of that property for all others).

Why does your new code not contain any event handlers?
0
 

Author Comment

by:Arikkan
ID: 40598913
It is a CSHTML and I am not very familiar with that.
I am just modifying some code done earlier.

But this works right:
        $(this).hide();
        other.show();

So, what do I need to add to the buttons to make sure I can read their selected state?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question