Question

I want to trigger a JavaScript function through changing HTML code.

This is what I do:

  1. There's a webpage with a button
  2. I click on that button which triggers a JavaScript function
  3. That function generates parameters which are put in the URL
  4. I retrieve those parameters from the URL in my serverside code which is made in Windev
  5. Windev generates a result which is added to the HTML code through regenerating the page

The result can be positive (in which case it's good), but if the result is negative (shows an error) then I want to trigger a JavaScript function from my Windev code. I wanted to do this by adding a call to the function in the HTML code through adding it from Windev.

So how do I trigger a JavaScript function in HTML? (Without using a button!)

Was it helpful?

Solution

I have a better solution.

Server Side

When there is error, you append a query parameter like error=1 to the end url.

If you have a page like nettpals.in/default, after encountering a error, you append a query string like: nettpals.in/default?error=1 (I don't know of how to do it in Windev, in fact I haven't even heard of it ! But you know what you are doing :))

Client Side

Use this javascript:

window.onload=function(){
  if(getParameterByName('error')=='1'){
    // do something
  }
}
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}

What does it do ?

First, if an error occurs, you append a query string error=1 to the url. In the client,

you are checking if the url has the error parameter. If so, it automatically executes the code that is inside the if condition.

Note: Replace the comment // do something with your code. AND since this code works on onload event, you won't need to trigger it(eg: with a button)

OTHER TIPS

I added another %-variable in the HTML code like this:

<body%4>

which I replace in Windev with the line:

onload="showMessageBox()"

showMessageBox() is the function which will be triggered which is what I meant to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top