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

  • SEARCH
  • Home
  • 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 7784581
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:07:04+00:00 2026-06-01T20:07:04+00:00

I have a form with a lot of inputs (text inputs, textareas, checkboxes…) that

  • 0

I have a form with a lot of inputs (text inputs, textareas, checkboxes…) that users can populate with their own presets. At the moment, users can search for their presets, an ajax query is called and I return HTML with a list of found presets. The HTML is (elaboratly) generated in a PHP file that adds an onclick="" with lots of different actions. The users can click the presets and the form gets populated.

An example of generated HTML (that gets put in the page) could be

<a onclick=" $('#AgendaItemName').val('Preset 1');  $('#AgendaItemOpmerking').val('');  $('#AgendaItemLokaalID').val('');  $('#AgendaItemPlaats').val('');  $('#AgendaItemBegeleidendeLeerkrachten').val('');  $('#AgendaItemDoelgroep').val('');  $('#AgendaItemIsPubliek').val('1');  $('#AgendaItemLesFicheAbonnementID').val('');  $('#AgendaItemAgendaItemTypeID').val('2');  $('#AgendaItemAgendaItemPublicatieTypeID').val('');  $('#AgendaItemLeergebiedID').val('1');  $('#AgendaItemLeerdomeinID').val('1');  $('#AgendaItemLessenTaken').val('');  $('#AgendaItemVerloop').val('Test verloop\r\n\r\ntest opslaan vanuit agendaitem');  $('#AgendaItemBeginsituatie').val('');  $('#AgendaItemMateriaal').val('');  $('#AgendaItemEvaluatie').val('Test evaluatie');  $('#AgendaItemEigenLesdoelen').val('Test lesdoelen');  $('#AgendaItemAgendaItemHerhaalModeID').val('');  $('#AgendaItemHerhaalStartDatum').val('');  $('#AgendaItemHerhaalEindDatum').val('');  $('#AgendaItemAgendaItemKleuterModeID').val('0');  UpdateVisibleFields('AgendaItem');$('.HoekVeldInput').val('');$('#AgendaItemAgendaItemBelangstellingsCentrumID').val('');  $('#AgendaItemLesFicheID').val('791');  $('#AgendaItemIsBestaandeFicheAanpassen').attr('disabled', false); loadFieldsets(791, 'LesficheID'); return false; " href="#">Preset 1</a>

You don’t actually have to fully read that piece of code, cuz it’s… well, not so good. Most of the times it’s just setting values, but sometimes, I also need to execute a few functions, depending on preset settings. Now I was thinking about a better way to approach this, but I’m stuck. Is there any way to send these actions along with JSON? Is it possible to do something like

var returndatafromajax = [
    {
        "html" : "<a href='#' rel="0">preset</a>",
        "actions" : "dothis(); dothat();"
    },
    {
        "html" : "<a href='#' rel="1">preset 2</a>",
        "actions" : "someofthis();"
    },
    {
        "html" : "<a href='#' rel="2">preset 3</a>",
        "actions" : "noneofthat();"
    }
]

$('ul').on('click', 'a', function() {
    var index = $(this).attr('rel');
    somehowexecute(returndatafromajax[index].actions);
});
  • 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-06-01T20:07:05+00:00Added an answer on June 1, 2026 at 8:07 pm

    Yes you can do this in this way

    var returndatafromajax = [
        {
            "html" : "<a href='#' rel="0">preset</a>",
            "actions" : {"1":"dothis","2":"dothat"}
        },
        {
            "html" : "<a href='#' rel="1">preset 2</a>",
            "actions" : {"1":"someofthis"}
        },
        {
            "html" : "<a href='#' rel="2">preset 3</a>",
            "actions" : {"1":"noneofthat"}
        }
    ]
    

    use only function names not the (); with their names.

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

Sidebar

Related Questions

I have a text field where a user inputs a value in the form
I have a form with a lot of options. In the form, I can
I have a very big form with a lot of inputs inside. Some of
I have a form with a lot of groups of radios. Each radio has
I have a form which I create manually (a lot of JavaScript in it...).
I have a form which contains a lot of elements, my DB guy has
I have a lot of check boxes in my WPF form. I want to
I have form where user submits field. Field can have letters, numbers, and punctuation.
I have form, where some fields are looks like rows, so I can add/delete
I have form with multiple input type=radio with text next to them. I want

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.