Javascript - updating values on a page
Posted: Sun Jan 16, 2022 2:49 am
I am working on a browser-based project that uses executables written in PB. My knowledge of html and javascript is limited. I have hit a stumbling block. This isn't really a PureBasic problem but the exe involved is written in it.
I have a html page that has a value displayed and a link which runs an exe program. (See below.) When the link is clicked, the exe is run. I would like values on the page to be updated without having to reload the entire page or load a new page. My problem is: how do I run the exe and then have the value updated without generating a new page?
Every time an exe is run via CGI the webserver expects a new page to be displayed. I would like the exe to run but not display another page, only update the current page.
Example below. The page shows one number 0 and a Change It link. Clicking on the link causes the exe program to be run. It picks up a parameter and changes a value in a sqlite database. That change does not have to be displayed. This part works ok. What then should happen is that the 0 should appear as a 1.
The only info I have found via Mr Google says that a new page must always be produced, either as a popup or another tab. The trick I have tried has a new 'child' page generated by the exe. That child page updates the values on the parent page then the child is removed by going back in the browser's history so it never appears. This seems cludgy and there must be a better way. It also does not change the value on the parent page.
Example parent page accessed via http://mycomputer/folder/test.html
<html>
<head>
<title>Test</title>
</head>
<body>
<p id='tobechanged'>0</p>
<a href="http:pbprog.exe?item=10">Change it</a>
</body>
</html>
The exe picks up the item=10 ok and updates the database. It then generates a response page as a string which is then sent via WriteCGIString in the exe. Here is a bit of the PB code.
A$="<html>"+#CRLF$
A$+"<head>"+#CRLF$
A$+"<title>CPAC</title>"+#CRLF$
A$+"<script type="+#DQUOTE$+"text/javascript"+#DQUOTE$+">"+#CRLF$
A$+" window.opener.document.getElementById('tobechanged')='1';"+#CRLF$
A$+"</script>"+#CRLF$
A$+"<script type="+#DQUOTE$+"text/javascript"+#DQUOTE$+">"+#CRLF$
A$+" history.go(-1);"+#CRLF$
A$+"</script>"+#CRLF$
A$+"</head>"+#CRLF$
A$+"<body>"+#CRLF$
A$+"</body>"+#CRLF$
A$+"</html>"+#CRLF$
WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_CGI_LastHeader)
WriteCGIString(A$)
The exe is working. This page is being generated. It doesn't appear in the browser due to the history.go(-1) script. But the value on the parent page is not changing. I am sure there is a more elegant and maybe simpler way to do this. I am just not clever enough to work it out. Searching with Mr Google has not helped. I've worked out how to pass values from a popup child window generated within the parent's html code but I have not been able to include the exe aspect.
Suggetions please?
I have a html page that has a value displayed and a link which runs an exe program. (See below.) When the link is clicked, the exe is run. I would like values on the page to be updated without having to reload the entire page or load a new page. My problem is: how do I run the exe and then have the value updated without generating a new page?
Every time an exe is run via CGI the webserver expects a new page to be displayed. I would like the exe to run but not display another page, only update the current page.
Example below. The page shows one number 0 and a Change It link. Clicking on the link causes the exe program to be run. It picks up a parameter and changes a value in a sqlite database. That change does not have to be displayed. This part works ok. What then should happen is that the 0 should appear as a 1.
The only info I have found via Mr Google says that a new page must always be produced, either as a popup or another tab. The trick I have tried has a new 'child' page generated by the exe. That child page updates the values on the parent page then the child is removed by going back in the browser's history so it never appears. This seems cludgy and there must be a better way. It also does not change the value on the parent page.
Example parent page accessed via http://mycomputer/folder/test.html
<html>
<head>
<title>Test</title>
</head>
<body>
<p id='tobechanged'>0</p>
<a href="http:pbprog.exe?item=10">Change it</a>
</body>
</html>
The exe picks up the item=10 ok and updates the database. It then generates a response page as a string which is then sent via WriteCGIString in the exe. Here is a bit of the PB code.
A$="<html>"+#CRLF$
A$+"<head>"+#CRLF$
A$+"<title>CPAC</title>"+#CRLF$
A$+"<script type="+#DQUOTE$+"text/javascript"+#DQUOTE$+">"+#CRLF$
A$+" window.opener.document.getElementById('tobechanged')='1';"+#CRLF$
A$+"</script>"+#CRLF$
A$+"<script type="+#DQUOTE$+"text/javascript"+#DQUOTE$+">"+#CRLF$
A$+" history.go(-1);"+#CRLF$
A$+"</script>"+#CRLF$
A$+"</head>"+#CRLF$
A$+"<body>"+#CRLF$
A$+"</body>"+#CRLF$
A$+"</html>"+#CRLF$
WriteCGIHeader(#PB_CGI_HeaderContentType, "text/html", #PB_CGI_LastHeader)
WriteCGIString(A$)
The exe is working. This page is being generated. It doesn't appear in the browser due to the history.go(-1) script. But the value on the parent page is not changing. I am sure there is a more elegant and maybe simpler way to do this. I am just not clever enough to work it out. Searching with Mr Google has not helped. I've worked out how to pass values from a popup child window generated within the parent's html code but I have not been able to include the exe aspect.
Suggetions please?