HTML variable validation

0

Good afternoon guys, are you okay?

I received an internal project and I can not finish it.

I have this excerpt from an HTML page:

    <span style='font-size:9.0pt;
    font-family:"Calibri",sans-serif;
    color:black>'>
    Apresente este QRCode no terminal de autoatendumento. Ele também está anexo. <BR>
    Identifique-se na <b><span style=font-size:11.0pt;>%%nomePortaria%%</b>, conforme ilustração abaixo.
    </span></span></p>

Just below this section, a gif of the selected concierge is displayed through the code below:

    <p align=center>
    <img name="imagem1" width=360 height=208>
    </p>

The question is: I need the gif to be changed according to the parameter passed in the %% nomeName %% variable. I created this very simple code to see if it would work, but it did not roll ...

<script>
function srcImage(path) {
    document.imagem1.src = path;
}

window.onload = function() {

    if(%%nomePortaria%%  == 1){
        srcImage('85.gif');
    } 
    else if(%%nomePortaria%% == 2){
        srcImage('86.gif');
    }
    else{
        srcImage('84.gif);
    }
}   
</script>

The images are in the same folder as the file, just for testing ... in the future, I will change the paths to a url of the correct images.

Thank you guys!

    
asked by anonymous 18.09.2018 / 18:17

2 answers

0

Hi, Arildo. I do not quite understand the scope of what you want, but only with HTML you can not solve it. The script you have declared is JavaScript and it is in it that you have to operate. You var need to have a variable to handle in the IF. You'll also need some way of changing the variable dynamically. What did you think?

<script type="javascript">
var nomePortaria = "1";
function srcImage(path) {
    document.imagem1.src = path;
}

window.onload = function() {

    if(nomePortaria  == 1){
        srcImage('85.gif');
    } 
    else if(nomePortaria == 2){
        srcImage('86.gif');
    }
    else{
        srcImage('84.gif);
    }
}   
</script>
    
18.09.2018 / 18:28
0

What happens is that you are mixing code backend with javascript.

A solution, it would be forçar this variable that comes from backend to be transformed into a javascript variable.

Place this line of script above the import of the code you are creating.

<script> var nomePortaria = %%nomePortaria%% </script>

And your validation script:

<script>
function srcImage(path) {
    document.imagem1.src = path;
}

window.onload = function() {

    if(nomePortaria  == 1){
        srcImage('85.gif');
    } 
    else if(nomePortaria == 2){
        srcImage('86.gif');
    }
    else{
        srcImage('84.gif);
    }
}   
</script>

Remember to put% valid% under the script where you created the variable.

    
18.09.2018 / 18:29