Solved

Selecting from buttons

Posted on 2015-02-06
2
40 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
Comment Utility
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
Comment Utility
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now