dynamic change variable from database - javascript

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.

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 can I dynamically control a Region Display Selector in Oracle APEX?

I'm hoping to select a particular Region to highlight on the page load based on the link the user follows to get to that page. This is a drill-down report with multiple options, so the goal is to have all options available but focus on the one the user selected to reduce the number of times a user has to navigate to/from the base report to the drill-downs.
Currently, I'm trying to implement this solution https://svenweller.wordpress.com.../, further explained in an Oracle Community discussion here: https://community.oracle.com/..., but it is not working for me.
What I have now is similar to what is shown in those examples, and for now I'm just trying to link to a static Region Display Selector (RDS) tab (the goal will be to have the selected Region be dynamic based on which link is clicked in the feeder page, but I'm clearly not there yet).
I have a Dynamic Action set to fire on Page Load event, and a True action that executes JavaScript code and uses the JavaScript in the example (both with and without the Timeout function suggested in the Oracle thread). I have set Static IDs for the RDS and Region, but when I load the page the RDS still defaults to Show All (or the first region if Show All is off).
Can someone help me understand what I'm doing wrong?
Thanks.
let sesStorage = apex.storage.getScopedSessionStorage({
useAppId:true,
usePageId:true});
setTimeout(sesStorage.setItem( "tabs.activeTab", "#R3" ) { apex.region("tabs").widget().aTabs("getTabs")["#R3"].makeActive();}, 300);
\\version without setTimeout
let sesStorage = apex.storage.getScopedSessionStorage({
useAppId:true,
usePageId:true});
sesStorage.setItem( "tabs.activeTab", "#R3" );
I have done something like this in the past. Create a hidden variable on the page P1_TEST, make sure to set the value not to be protected.
You will need to set the value of that variable when the link is clicked.
Then you need to add static IDs TAB1, TAB2 etc. to the tabs of you region display selector.
Then add a DA on Page Load:
if (apex.item("P1_TEST").getValue() === "Value1"){
$(".apex-rds [href='#TAB1']").trigger('click');
} else if (apex.item("P1_TEST").getValue() === "Value2"){
$(".apex-rds [href='#TAB2']").trigger('click');
}

How to use a button to come back to the index, checking the pagination table of a specific ID?

I have this problem: I use Yii2 and, when I go to an index page, I select a view for an element (Example, I go to the page 4, because I want to enter in the view of the element with ID 41, which is at the page 4 because I have the pagination set to 10). This is ok for me but, when I enter in the view, I have this link to come back to the index:
<?= Html::a ( "Back", ['codici/index/','CodiciSearch[IDCodice]='=>$model['IDCodice']], ['class' => 'btn btn-primary']) ?>
Actually, this return to the index, but it show me only the record with the ID that I pass to the link. So, in this case, only the record 41. I want, instead, that the Back button turn to the previous page checking the pagination in which I was, and not only the ID. So, the link must checking the pagination of an ID. I hope to be clear. I don't need a solution like "window.history.go(-1)" because this create a problem if I came to the view by another way. I would to have a specific option: the link must to return to the index and get the pagination of an ID (so, in this ex. case, to the page 4).
I hope to be clear. Thank you in advance!!!!
Here are the solutions I use:
most times I just open the target page in a new tab. That is the simplest solution. If this is acceptable then simply add a parameter to the Html::a options as follows:
Html::a(“text”,[url],[‘target’=>’_blank’]);
Note: if the link is within a Gridview you need to set the format to raw (“format”=>”raw”)
on the index page, pass the pagination number to the new page.
Html::a(“text”,[url, ‘index_pagination’=>5]);
You can then use this in your button
instead of passing the pagination, you can capture the referring page and send the user back:
$url = Yii::$app->request->referrer
This is easy but it can cause challenges if the user reloads the page in which case the referring page is the current page.

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.

PHP-JS Button click take onyl the last inserted value

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.

Categories