ReferenceError:在HTMLInputElement.onclick上未定义显示

时间:2020-01-21 15:56:40

标签: javascript php html

我遇到了问题(我在寻找答案,但没有人为我工作)。 如此,我试图通过添加功能来解决此问题,但同样的问题,我真的不知道为什么会得到这个。

控制台日志中的错误:

ReferenceError:未在HTMLInputElement.onclick上定义显示

HTML代码:

<center><h2 id="select_template">Do you want to choose an activation template?</h2></center>
            <br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('vps')" id="vps">
                        <label class="custom-control-label" for="vps">Virtual Private Server</label>
                    </div><br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('webhost')" id="webhost">
                        <label class="custom-control-label" for="webhost">Web Host</label>
                    </div><br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('mcgmsv')" id="mcgmsv">
                        <label class="custom-control-label" for="mcgmsv">Minecraft Game Server</label>
                    </div><br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('license')" id="license">
                        <label class="custom-control-label" for="license">License</label>
                    </div><br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('downloadsft')" id="downloadsft">
                        <label class="custom-control-label" for="downloadsft">Downloadable Software</label>
                    </div><br>
                    <div class="custom-control custom-checkbox small" style="display: inline-block; text-align: left;">
                        <input type="radio" class="custom-control-input" name="searchValue" onclick="display('domain')" id="domain">
                        <label class="custom-control-label" for="domain">Domain</label> 
                    </div><br><br>

JS代码:

<script type="text/javascript">
    /*
    TEMPLATING      
    */
    function display($value) {
      if($value == "vps") {
        document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose Virtual Private Server!`;
        document.getElementById("info_to_customer").value = `Thanks for your order (#<?php echo $svdo_id;?>)!

Server Details:
IP: -
User: -
Password: -

Panel Details:
Email (Panel): -
Password (Panel): -

        Control panel: <a href="https://LINK TO PANEL" target="_blank"><b>CLICK HERE</b></a>`;

      }
      else if($value == "webhost") {
        document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose WebHost!`;
        document.getElementById("info_to_customer").value = `Thanks for your order (#<?php echo $svdo_id;?>)!

Web Hosting Details:
Email (Panel): -
Password (Panel): -

Control panel: <a href="https://LINK TO PANEL" target="_blank"><b>CLICK HERE</b></a>`;

      }
      else if($value == "mcgmsv") {
        document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose Minecraft!`;
        document.getElementById("info_to_customer").value = `Thanks for your order (#<?php echo $svdo_id;?>)!

Minecraft Server Details:
IP: -
Port: -
Email (Panel): -
Password (Panel): -

Control panel: <a href="https://LINK TO PANEL" target="_blank"><b>CLICK HERE</b></a>`;

      }
      else if($value == "license") {
        document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose License!`;
        document.getElementById("info_to_customer").value = `Thanks for your order (#<?php echo $svdo_id;?>)!

License Details:
License Key: -`;

      }
      else if($value == "downloadsft") {
        document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose Downloadable Software!`;
        document.getElementById("info_to_customer").value = `Thanks for your order (#<?php echo $svdo_id;?>)!

Software Details:
Download Link: -`;
      }
      else if($value == "domain") {

            var svdo_type = '<?php echo $svdo_type; ?>';
            var domain_string = "{DOMAIN}";
            if(svdo_type == 'domain' || svdo_type == 'Domain' || || svdo_type == 'DOMAIN')
            {
              domain_string = "<?php echo $svdo_name; ?>";
            }
            else
            {
              domain_string = "{DOMAIN}";
            }
            document.getElementById("select_template").innerHTML = `<font color='green'><i class="fa fa-check"></i></font> Good, so you choose Domain!`;
            document.getElementById("info_to_customer").value = `Thanks for your order!!

Domain Details:
Domain Name: ` + domain_string + `

Control panel: <a href="https://LINK TO PANEL" target="_blank"><b>CLICK HERE</b></a>`;
        } 
      else
      {
        document.getElementById("select_template").innerHTML = `<font color='red'><i class="fa fa-times"></i></font> Invalid template on your choice, please check another one!`;
      }
    }
  </script>

函数display已定义,会发生什么? 谢谢。

1 个答案:

答案 0 :(得分:0)

在您的js脚本中,您有以下内容:

if(svdo_type == 'domain' || svdo_type == 'Domain' || || svdo_type == 'DOMAIN')

删除多余的||

另外,您有以下几行内容:

 document.getElementById("info_to_customer").value = 

没有ID“ info_to_customer”