Clicking a button from JavaScript/JQuery by name rather than id - javascript

I'm developing a kind of online store in which adding items to carts are carried out by an Ajax method. I'm using ASP.NET MVC and in my Razor view engine I Require to have many submit buttons with the same ID (for some reasons) but with different names to distinguish them problematically. These buttons are used to fire the Ajax method at different areas in the same page. When they are clicked, they set some value to a hidden submit button (the ones that share the same ID) and then fire them. I need to fire these button based on their names, for example
//Instrad of
$("#ID").trigger("Click")
//I trigger click them by their `name` attribute.
I know how to get the values or other attributes of an element by name, but so far I have no clue on how to trigger a button by name. So I wanna know if that's possible at all and how it can be done.

Try below
$("button[name='btnName']").trigger("Click");

Related

CheckboxList not retaining it's check mark on postback

Checkboxlist control in a repeater control & ASP.net C#. Whenever I check its items it gets uncheck automatically. I am also calling this method when the page is not postback as well but it is not working & gets uncheck although I get the values but clears out the checkmark. I do not want to use the session.
If you are in page load re-binding the repeater then you lose the settings. So you need to only bind on first load
(if IsPostBack = false then databind)
So if you re-bind the check boxes each time, then you lose their settings. The other way is to create a array or better yet a dictionary pair list - when you check a item, ALSO save that setting in the dictionay list based on row index. Then you can re-bind on load or as you like, and in the row data bind event, you set the value of the check box based on the dict pair list you maintain (you have to save that list in viewstate or session).
So, it is MUCH less work to simply ensure that you ONLY fill + bind on first page load. If you at any time re-bind the repeater, then you lose your settings. So they will persist ad survive round trips (post-backs), but ONLY if you bind one time on first page load.
It not all that hard to build up a "list" of you made choices and then on row data bind event check + set the values from that small list of choices. But as noted, it obviously easier to just avoid re-binding. However, in the cases that you can't avoid a re-bind, then you need to write your own code to persist the choices.

Change value in table on Button click in Acumatica

I am creating a Scan In and Out form in Acumatica as a custom screen. They are two separate screens and both are just a standard form.
They are both setup as follows: One field that is a selector where you select the Key ID of the data row you want to modify such as a Work Order. Once you click Scan In it will change the value of a field in that data row for the Key ID you selected let's say, the status field saying that it is being processed for Scan In button click and closed for the Scan Out button click.
My question is, is it possible to do this with just a click event. I mean the save button commits changes to the database but this does not have a save and is only changing one field of a specific data row.
If anyone has suggestions or can point me in the right direction that would be great! Again this is all in Acumatica so I feel the Graph or View will have to be modified?
Once in my company we did something similar, i know this is not the best option based on acumatica way, but what we did is to execute a direct SQL query from the action (in your case the click button) to update/insert something in database. I think the best option for you would be use Ajax, but i don't know if acumatica has this functionality.
In your action that is changing the status of the row, after changing the status, you can call an update to your view (ViewName.Update(targetRow)) that is used to populate the page with the information you are looking at. After you can programmatically trigger a page save using this.Actions.PressSave().

How to record user actions and then re-execute them in JavaScript?

I have a web page (all done in client side code) where users can add certain page elements dynamically through different buttons.
For example, they can click a button called "Add Group" and input a group name. This will create a <div class="customGroup"> that displays the group as the "title" among some other buttons that let them add even more elements within that newly created <div>.
I want to be able to store what a user did and not have it lost if they do something like close & reopen the window or reload the page. So for example, if they add a group "Foo" and refresh the page, given that the page is all HTML/JavaScript, "Foo" is lost.
Is there some way I could record their actions and re-execute them using caching/cookies? Or do I need to do it some other way? Is this even possible?
I would suggest using localstorage to keep this data around, across windows opening and closing.
You can find out what the user clicks on by attaching an event listener to the elements you care about. The functions you pass in there can keep references to the clicked items by pushing them to an array. Then you can click them when you want to using .click().
As for text the users enter when the data is submitted, make sure its in localstorage as a string. On page load, you can put this data wherever you want to, so give it to an elements innerHTML and voila, you can reconstruct the page state.

Programmatically firing a client-side event

I have a typical ASP.NET web form application. It has about 20 separate user controls (.ascx files), each one containing a DetailsView control. One of the requirements of this application is that there needs to be a single Edit, Update, and Cancel link outside of those user-controls, which, when clicked, will cause each of those DetailsView objects to go into the correct mode, Edit or ReadOnly, and, if Update was clicked, do an appropriate database update. In other words, clicking that "global" link has to programmatically fire the client-side click for each of those corresponding links that you get "for free" when you create a DetailsView or GridView. I've tried copying the actual __doPostBack event that gets invoked when you do use one of those "internal" links, assigning it to a string, doing a Page.ClientScript.RegisterScriptBlock, then doing a LinkName.Attributes.Add("onclick", "script_string_name") -- but I just can't get it to work. What is the correct way to accomplish this?
You can use the asp:linkbutton control to do this.

select all checkboxes of a form

In my rails application, i am displaying some records. I am using pagination for records..
i have a javascript function to select all the checkboxes associated with a record..But it selects checkboxes of only current page. I want to have a feature where i can select all the checboxes of current page and then move to next page selec there and then submit all of them together.
I'd say hopping between pages and selecting everything is way too tedious and extremely error prone.
Have your "Check all" function submit something like a yourform[check_all]=true parameter to your controller (via ajax or plain HTTP POST) and have your controller handle the requested action on all relevant records.
Recently I have done the same task as you. I am using table with Ajax pagination, so I can remember all checked positions in array or other object. Then I've added on-click handler to submit button where hidden fields are adding to form to make the same effect as missing checkboxes.

Categories