Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6619603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:59:26+00:00 2026-05-25T20:59:26+00:00

Afternoon All I have some data – var searchwithin = [ {id:clearwithin, type:button}, {id:search_radius,

  • 0

Afternoon All

I have some data –

    var searchwithin = [
{id:"clearwithin", type:"button"},
    {id:"search_radius", type:"select"},
    {id:"for_lease" ,type:"checkbox"},
{id:"for_sale", type:"checkbox"},
]; 

It is going to be showing and hiding informtion dependent on what is clicked (this is only a small fragment of the data.

I have already worked out how to check the type property, what I want to know is the following:

If the type is button, how do I access the id value for that items and then generate a click function so that that uses the id as the name of the button to associate the function with.

Thanks in advance

Phil

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T20:59:27+00:00Added an answer on May 25, 2026 at 8:59 pm

    First, fix a syntax error in your searchwithin table by removing the comma after the last item in the table. That will cause an error in IE6/IE7.

    Then, you can use this code to look through your searchwithin array to find the id for the appropriate type and then set a click event handler for that id.

    var searchwithin = [
        {id:"clearwithin", type:"button"},
        {id:"search_radius", type:"select"},
        {id:"for_lease" ,type:"checkbox"},
        {id:"for_sale", type:"checkbox"}
    ]; 
    
    function findIdByType(target) {
        for (var i = 0; i < searchwithin.length; i++) {
            if (searchwithin[i].type === target) {
                return(searchwithin[i].id);
            }
        }
    }
    
    var id = findIdByType("button");
    if (id) {
        $("#" + id).click(function() {
            // do whatever you want to do on the click function here
        }
    });
    

    I notice that your table has two entries for type:checkbox. The above code suggestion will return and operate on the first entry only. If you want to set up click handlers for both those IDs, then either the code or table would have to be modified. If this is all the table is used for, it could be changed to be a selector (which can contain more than one id) like this:

    var searchwithin = [
        {id:"#clearwithin", type:"button"},
        {id:"#search_radius", type:"select"},
        {id:"#for_lease, #for_sale", type:"checkbox"}
    ]; 
    
    function findSelectorByType(target) {
        for (var i = 0; i < searchwithin.length; i++) {
            if (searchwithin[i].type === target) {
                return(searchwithin[i].id);
            }
        }
    }
    
    var selector = findSelectorByType("button");
    if (selector) {
        $(selector).click(function() {
            // do whatever you want to do on the click function here
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good afternoon all. I have a page that displays data in a gridview based
Good Afternoon All, I have two tables in my SQL Server 2005 DB, Main
I have been trying all afternoon to get the jQuery Sifr Plugin ( http://jquery.thewikies.com/sifr/
Afternoon all. I have the following scenario: I have a search page where by
Good Afternoon All, I have a wizard control that contains 20 textboxes for part
Afternoon All, I have a stored procedure in an SQL 2005 database named GasNominationsRawData_Insert.
Good Afternoon All, I have written an SSIS 2005 package that contains a conditional
I have been trying all afternoon to try and achieve this with no success.
Afternoon all. Another hour, another question! I have the following bit of jquery up
I have had that weird error this afternoon... I cannot figure out why System.Data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.