PHP-JS Button click take onyl the last inserted value - javascript

First of all sorry for my bad english ^^
I've a table named CLIENT with some records. Coloumns of the table are ID-NAME-DESCRIPTION
My purpose is to edit these record, with a button EDIT which is located in another column next to the record. I have a button for each record.
At the click of EDIT button I want that clients data (NAME-DESCRIPTION) will be displayed in a form (that have 1 textbox for NAME and 1 textarea for DESCRIPTION).
In this way, with edit button I'll edit the values of the record, but this it's another thing, not important now.
The problem is that, whatever the record associated with the edit button in the table, in the form It's showed only the data of the last customer on the table. No matter what if I click the first, second or another record .... it always displays the last.
I do all the procedure in the same php page, using javascript for show the values in the form.
Pratical expample.
NAME DESCRIPTION EDIT
Cat Kitten button
Dog Puppy button
If I click the button of cat, or the button of dog, in the form I see dog puppy...the last record.
Here the code.
Table with the script
http://pastebin.com/44xCC3aw
Form where I want see the values of the record
http://pastebin.com/vNTimhJ5
Thank you in advice

You are using PHP (server-side) and Javascript (client-side) with eachother. This is a bad idea.
You are now overwriting the Javascript function funzione by having the PHP side loop through it and creating the same function over and over.
A better practice would be to have the function generate once, and retrieve the information from the server when you've clicked on the button. This is common practice and done using AJAX.
In the less save solution, you could keep an array (created by the PHP part of the script) in Javascript, where you keep track of the IDs. You then make sure you have only 1 function funzione that takes an ID like this: funzione(id). The function retrieves the ID from the created array and shows the correct information in your textfields.

Related

Oracle Apex20.2 wizard when going back from form 2 to 1 the input fields in form 1 needs to retain their original values how to do this?

I’m fairly new to Apex but struggling with the wizard part.
I'm currently using apex 20.2
I have a wizard that works perfectly fine, passing item values from one form into another form item
I’m doing this with branches where in the behavior I set the value of the current form into the next one.
But somehow I cannot do it with the ‘previous’ button.
I would assume I could do the same, pas the item value from form 2 into the items from page 1
Then use that value as default item value?
But then I get an error saying there is no data.
Can someone point me in the good direction?
Thanks.
when pressing the previous button the action is a redirect to page 12, i would need to pass that P10_NAME value into form item P12_NAME
In Page 12 a was assuming i would need to set a default to the item where i have passed the data in?
With a link, the target is generated at page rendering time. It does not pick up the current values in the form.
Instead what you could do is
Change the button action to "Submit Page"
Create a pl/sql page process to set the values (point: processing, condition when button pressed)
Create a branch to redirect to the previous page (point: after processing, condition when button pressed)
The 2nd bullet is optional, you can also pass the values in the branch link. Since the branch is executed after processing the item values will be the new item values (and not the values at page rendering time you see in the link now)

How do i pass the text inside a html tag to another page and update that page with the text?

To further explain,
I have text that says "Cart(0)" every time someone clicks a button the number increments when I click "Cart" I want it to take me to a new page while sending the text "Cart(1)" (say someone added one item). I want it to show Cart(1) on the next page and pass that value over.
<li><a id="cart" href="cart.html">Cart</a></li>
I have a javascript file that increments and updates that text like so:
function addToCart(){
++cartcount;
document.getElementById("cart").innerHTML = "Cart("+cartcount+")";
}
Now when I click the cart it should take me to another page and still have whatever number beside the cart and store the number in a variable that I can use.
Any help would be greatly appreciated. I saw many questions but they were hard to understand in my context.

Dropdown-List - Multi-Selection should add text to Textbox in several Lines

Hello everybody! :)
I've made an easy random Drop-Down-list on our "Price-Request-Site" with all the Items in the List that we sell to our Customers.http://i.imgur.com/qg5jj0p.jpg
And because they need to request Prices for those items, they can select one or more items from the Dropdown-List and the Output goes to a "simple Textbox"
You have to Select one or more Items from that DropDown-list and the JavaScript should "paste" the selected List-items to the Textbox.
The Textbox is already a part of a "Formular" to send the Textbox-input as an E-mail.
My JavaScript does the following at the moment:
If click an Item from the List, the Item-name appears in the Text-box in the first Line.
If I click a Second OR/AND another item, the JavaScript will overwrite the now existing "Item/Textline" from the first Line in the Textbox.
http://i.imgur.com/9DoY7cS.jpg"
I need the following solution to my JavaScript and it should be easy as possible:
When I click to another Item from the List, it should be added to the Second Line, When I click another Item, it should be added in the next (3rd) Line...
Background-information:
This Script should make it easier for the Customer to write a Price-Request-EMail to us.
(Without searching through the Shop and looking for or Article-Numbers, instead he can choose Products from the Dropdown-list with an Output to this Email-form/textbox)
function favsports()
{
var mylist=document.getElementById("mylist");
document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
}
I would be very Happy if someone could help me with my issue, i'am really new to JS :D

Select HTML Table Row and Identify DB Record ID

I’m developing a simple CRUD based application for upskilling purposes.
Currently, the application outputs the result of a select query to a HTML table using JSTL. The last column of this table has a Delete link for each record which sends the parameters action=delete&id=1 to the server. The id param value part of the href of these links are obviously dynamically generated with JSTL based on the database record key that is passed into the JSP with the database results.
Instead of having this Delete column, I want the user to “select” a row and click a Delete button at the bottom of the table, which will send the above parameters to the server.
I am unsure how to accomplish the following to achieve this:
(1) In Javascript, how can I allow the user to “select” a table row. I don’t want the table to have radio buttons. The behaviour should be that the user clicks the row, the entire row colour changes and JS retains the index of the selected row. Only one row can be selected at a time. If the user clicks the row again, it becomes deselected, i.e. the colour is returned to its original colour and JS no longer identifies that row index as being highlighted.
(2) If I don’t have a Delete link specific to each db record, how can I identify the key of the db record to be deleted and return this to the server when the Delete button is clicked. For example, currently if the record in the db has an PK of 123456, my JSTL will generate a href action=delete&id=123456 for that specific Delete link. So, how can I link that id to the selected table row without having to actually display that id in the HTML table.
1) There are plenty of ways to do it. I suppose all of them will involve the use of something like var rows = document.getElementsByTagName("tr"); or its jquery (or other framework) equivalent. Or some other selector, maybe by CSS classname, could be used. Followed by a loop in which you deselect all the rows that were not clicked and select only the one that was recently clicked. Changing the color equals just changing the css class assigned to the DOM element basically.
2) You will use Javascript either to append to the DOM an html form with hidden inputs (<input type='hidden'.../>) and then submit it via Javascript (if you're Ok with moving to a different page and back). Or you can use Javascript to send an Ajax request to the delete servlet, and then remove the particular tr from the page when you receive a success response back.

dynamic change variable from database

is there possible that changing a Javascript variable or PHP variable dynamically and show it up to user without reloading the page?
I know there are a lot about this topic and everyone seems suggest using AJAX, but I think my case is different or I could say I can't find the correct answer of my problem.
The case is, when user click a button named "go", user will jump to page2 which showing a number from a variable. Every person who click "go" button will make that variable going up by 1.
if(button == pressed){
mysql(update row1++ on a table) << update query that change value of row1, row1 is an number or integer
jump to page2
}
in page2 will showing the variable value and dynamically change.
select(row1 from a table)
variabletemp = row1
print variabletemp << this has to be dynamically.
I read some of another question, I can do this trick using AJAX. Put the variable value on database, and then update it ever second which the second is set by interval function.
But the problem is, I want to change the value of variabletemp when the database is updating without interval function when the user is in page2, and after the variabletemp value reach some number, lets say 4, the user who already in page2 will jump into page3 (another page).
if(variabletemp == 4){
jump to page3
}
Is that possible? It will be great if you put some example. I use Javascript for showing the variable, and processing database through PHP.
from what i understand you are trying to "push" data to the users?
if so Comet / Reverse Ajax is what youre looking for.

Categories