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 7179789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:12:43+00:00 2026-05-28T17:12:43+00:00

I have got four buttons in my html. Create Airport Create City Create City

  • 0

I have got four buttons in my html.

  1. Create Airport
  2. Create City
  3. Create City Shortname
  4. Create Airport Shortname

All of the button will give ajax call to same page and below is the code written for one of the button.

 $('#imgbtnCreateAirport').click(function (event) 
    {        
    if($('#hidtext').val()!= 'true')
        {
        var file = $('input[type=file]').val(); 
        if (!file)
        {
            $('#lblCreateKeywordsError').html('Please select the excel file from top.');
            event.preventDefault();
            return;
        } 
       else if (!file.match(/^.*\.xls[xm]?$/)) 
       {
            $('#lblCreateKeywordsError').html('Please select excel file only!');          
            event.preventDefault();
            return;
       }
        else
        {
        $('#lblCreateKeywordsError').empty();
        var strInput = "";
        strInput = strInput + "?cck=CreateAirportKeys";
        var serviceReq = "/TridionCustomPageWeb/Exceldata/excelupload.aspx";
             $.ajax({
                url: serviceReq + strInput,
                contentType: "application/json; charset=utf-8",
                dataType: "jsonp",
                jsonpCallback: "processcck",
                beforeSend: function()
                {     
                    $("#hidtext").val('true');                  
                    $("#imgbtnCreateAirport").attr('src', 'images/processing.gif').attr('alt','Processing...');                      
                },
                success: function(data, textStatus, jqXHR) 
                {    
                    $("#hidtext").val('false');                
                    $("#imgbtnCreateAirport").attr('src', 'images/CreateAirport.jpeg');
                    if (data.result=="CreateAirportKeys")
                    {
                        alert("Valid")
                    }
                    else
                    {
                        alert("Invalid");
                    }                   
                },
                error: function(jqXHR, textStatus, errorThrown) {
                alert(textStatus + "---" + errorThrown);
                }
            });
            return false;
            }
            event.preventDefault();
            return;
            }
            else
            {
                alert("Please wait till other process is completed!!");
                event.preventDefault();
                return;
            }
    });

Now in above other than two things all the code will be same for every button, and below are the two thing will be different

strInput = strInput + "?cck=CreateAirportKeys"; //here CreateAirportKeys part will be different in every button call
$("#imgbtnCreateAirport").attr('src', 'images/processing.gif').attr('alt','Processing...');  // here $("#imgbtnCreateAirport") will be different.

I tried to make jquery function. but I was not able to make because of ‘event.preventDefault();’ as I was not able to get it in function.

Please suggest how can I write a function which will have event.preventDefault(); as well parameters for above two fields.

Thanks.

  • 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-28T17:12:44+00:00Added an answer on May 28, 2026 at 5:12 pm

    You can make a function that contains all your logic that you can call from each event handler and pass it in the specific parts that are different:

    function processButton(event, inputStr, btnCreate) {
        // all your code goes here and it uses the three arguments passed in
    }
    

    And, then for each event handler, you can do this:

    $('#imgbtnCreateAirport').click(function (event) {
        return(processButton(event, "?cck=CreateAirportKeys", "#imgbtnCreateAirport"));
    }
    

    As you can see, each click event handler calls the common code and passes in the three parts that are different, the event object, the string and the id value. For the DOM object, you could probably also either just pass this if you wanted it to always be the actual object that was clicked on or you can obtain that object from the event also.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have four columns and four buttons I got them to all line up
I got these four errors when I tried to create a button on the
I have got a C function in a static library, let's call it A,
I have got some code to load an assembly and get all types, which
I have got four classes A , B , C and D . Class
I have a date of operation. I want create promissory notes which have got:
I have got four tabs. I was able to change the tab icon color
I have four Buttons that display the the date/time of calendars which are attributes
I have got four routes defined like this: //Project list with page number routes.MapRoute(
Have got an NSString *str = @12345.6789 and want to find out if there

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.