This topic is locked
[SOLVED]

 Embedded JavaScript Question

4/29/2020 7:40:18 PM
PHPRunner General questions
S
salus1 authorDevClub member

If a text field is configured to View As HTML and the example code from...
https://www.w3schools.com/js/js_validation_api.asp
...is entered in to the text field the JS functionality seems to be disabled when the project is rendered.
See https://www.customdataservices.net/restapisdb/base_list.php for example
The code as entered in the View As HTML text field...
<p>Enter a number and click OK:</p>

<input id="id1" type="number" min="100" max="300" required>

<button onclick="myFunction()">OK</button>

<p>If the number is less than 100 or greater than 300, an error message will be displayed.</p>

<p id="demo"></p>

<script>

function myFunction() {

var inpObj = document.getElementById("id1");

if (!inpObj.checkValidity()) {

document.getElementById("demo").innerHTML = inpObj.validationMessage;

} else {

document.getElementById("demo").innerHTML = "Input OK";

}

}

</script>
I know it's an odd ball question but I'd like to be able to use some pre-existing JS-based forms in an upcoming project and need to figure this out.
Thanks, as always, for any guidance you can provide.

Sergey Kornilov admin 4/30/2020

This should be your first step while dealing with Javascript:

https://xlinesoft.com/phprunner/docs/troubleshooting_javascript_errors.htm
Also, are you saying you storing your Javascript code right in the database? This would be both strange and wrong.

S
salus1 authorDevClub member 4/30/2020

Strange and wrong is my middle name.
Storing a customer's pre-existing forms in the database means I can provide secure access to them while saving a tremendous amount of time by not having to alter anything.
To clarify the problem, if I save the code below as a text document with a .htm suffix and open it in a web browser the inline JavaScript validation works.
<p>Enter a number and click OK:</p>

<input id="id1" type="number" min="100" max="300" required>

<button onclick="myFunction()">OK</button>

<p>If the number is less than 100 or greater than 300, an error message will be displayed.</p>

<p id="demo"></p>

<script>

function myFunction() {

var inpObj = document.getElementById("id1");

if (!inpObj.checkValidity()) {

document.getElementById("demo").innerHTML = inpObj.validationMessage;

} else {

document.getElementById("demo").innerHTML = "Input OK";

}

}

</script>
Insert the same code in a MySQL text field with PHPRunner output configured as View As HTML and the validation doesn't work. All the HTML forms I've stored in databases in the past and Viewed As HTML this way work as expected, trying to figure out specifically why in-line JavaScript doesn't and if it can remedied. I read the Help file before opening the thread but I didn't see anything that applies to this specific situation.
Thanks for any additional light you can shed.
Best regards

Rob

S
salus1 authorDevClub member 4/30/2020

Actually, had another coffee and realized that, thanks massively to the design flexibility that PHPRunners collapsible menu system provides, I could i-frame external content instead of embedding it. Virtually the same diff, display-wise.
Really simple, works perfect.
Thanks!

Sergey Kornilov admin 4/30/2020

Not the best idea either. There are multiple validation options built-in and there are Field Events where you can perform any kind of field related calculations including validation.

S
salus1 authorDevClub member 4/30/2020

I hear you but I use a lot of Excel-based web forms (spreadsheets converted to JavaScript with SpreadSheetConverter add-in), some with seriously exotic formulas, calculations, look-ups. You can see a good example at...
https://valucalc.com
Duplicating this level of functionality in other software would be pretty daunting. As it turns out using PHPRunner to provide secure login, search, and navigation control to i-framed external content works about as perfectly as it could, especially with PHPRunner's collapsible left menu (genius).