Solved

Selecting from buttons

Posted on 2015-02-06
2
46 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:SHANCHAT972
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:SHANCHAT972
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
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 benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

679 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