passing variable to jQuery from same Class - jquery-ui

I have googled for 2days so far :) Not finding the right answer yet. So expert help is needed.
I am writing the webpage, where I use php and mysql. On the webpage, it display list of products. Next to each product there is a button called "Compare". When user press the button, it should pop up the dialog box and ask user to enter some info then user click submit or cancel in the dialog box. When user click submit in the dialog box, it should take user to another page, where he will be displayed with information he is looking for (hopefully)....
For dialog box I am using jQuery-ui dialog box. The challenge I am facing is when user click on "Compare" button, I need to pass the product information to dialog box. Because all the product info are extracted from mysql and loop with php to display, they all have same class. eg
product 1Compare
product 2Compare
So how do i know which product_info i need to pass? I thought of adding attribute to button and product info with number to distinguish which one is selected, then i need to have multiple multiple dialog function attached to each button.
Any thought will be much appriciated.
Thanks

Create a global variable to store the index.
When we click on any button, we will check it's index and store in it.
After opening the popup or just before showing the popup, access this index. Using this index, access the division in which the product contains. Get required details from there. Update data in dialog box. Show dialog box.
Also clear global variable when you close the dialog box.
You can get more information about index here : http://api.jquery.com/index/
Friends, please suggest better solutions if any.
Thanks.

Related

Modal creating a log without changing the page

My page display a list of question. Near each question, a button switch a hidden statement to display a model over the page asking for some information. The goal would be, after the user complete the information and click submit, to access the backend and send the information to the database WITHOUT loading another page. I would like this popup to close and the user to resume what he was doing as if he did not do anything.
How would I go about doing something like this ?
You can use ajax and send a Post HttpRequest to an action which would then be tasked to save those information.
Please refer to this thread and this for more info.
Hope this helps you.

Handling the back button while using multi step remote links

I have a 3 step report which loads by clicking a link with the remote: :true option, so it reloads a part of the page instead of refreshing the whole page. I also provide the user with breadcrumbs, so he/she can easily navigate between the steps. However, most users use the browser back button, which of course reloads the whole page. What is the "Rails way" of dealing with this? If the browser back button is clicked the user should see the previous step in the report.
If you need to control the history the user sees, but aren't doing full page reloads on form submit, you should be manipulating the history state via Javascript's history.pushState and friends.
Assuming the responds to the submitted form is some sort of evaluated Javascript, simply include the history state manipulations there.

jquery mobile - MVC: How to save input from popup dialogs

Newbie here, scratching my head on this one.
How do you normally save information specified in a popup dialog for use by other forms on your page?
Scenaro:
Click an options button, which pops up a dialog.
Set some checkboxes, radio buttons, etc...
Submit form (dialog seems to need it's own form)
Do you usually just save the inputs in a session, cookie, or do you have another way access your dialog controls from the main form?
Seems like I'm missing something basic, as it should be easy to set some options and use them on the rest of the page.
All advice appreciated!
If you are trying to pass data from one page/dialog to another see Passing parameters between pages

How to use submit button in grails with if-else statement?

I am now currently working on a grails project. I have a problem with my <g:submitButton> tag, and I am using a web flow. What I wanted to do is to proceed on the next page using <g:submitButton> if the input from the user is 1, while display a pop up window with options OK and Cancel buttons if the input is 0. If Ok button is clicked, the user will be redirected into a certain page, same through if the Cancel button is clicked.
Have anyone tried this?
Please help!
I guess you need some javascript in your form tag for this functionality. Search for “html form onsubmit“ and you'll find some good resources.

Concept for a grails app

I am working on a Grails project, its an accounting project. We have multiple clients and they can have multiple types of accounts. I have to create the 'create' page for client, there should be a way to add multiple types of account to the client.
So I was thinking of making a drop-down list with account types and few text boxes to enter account name and other info about account. Also, as a client can have multiple accounts, so I want to create a 'add' button, when clicked it would display a new row to add a new client. I have done this kind of UI before using javascript but in this case, as there is a drop-down list and other components, I think it would be very hard and may not work.
I was thinking of creating a partial view which would render each time user clicked the 'add' button with additional row, problem with this would be during validation errors, edit page and i would also have to pass all values each time user clicks 'add' button.
Is there any other for doing this?
For the template approach you must use ajax if you don't want to carry on the params that the user has already set.
It is possible to make new drop-down lists appear (or any group of elements inside a <div>) when a user clicks a button, since Grails already comes with jQuery you might want to take a look at the .clone() method.
The problem with the two listed approeaches is that it will be possible to have duplicates.
Now, another option is to use checkboxes, so you can check just the type of account you want.
But to be honest it does seems a bit odd or even inapropiate to let the user choose the type of account he wants with such freedom.

Resources