Solved

Selecting from buttons

Posted on 2015-02-06
2
49 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 42

Accepted Solution

by:
David S. earned 500 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position items using CSS's three positioning types Create a new HTML document with an internal stylesheet.: Create another div in CSS and name it Absolute : Type "position:absolute;" and "top:10px; left:50p…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

623 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