doucan8049 2011-06-03 07:28 采纳率: 100%
浏览 68

JavaScript函数没有执行

I need an extra set of eyes here. I've been over this numerous times with no success. The issue is the getFilename function, which as the name suggests, is supposed to get the file name of the uploaded file. No matter what I do, it doesn't seem to work, so I must be missing something.

<?php
    $data = $_GET["data"];

    if($data)
    {
        echo '
            <head>
                <style>
                    .atklf
                    {
                        color: Red;
                        background: #292929;
                        border: 1px solid Red
                    }
                </style>
            </head>
            <iframe name="fuh1" style="display: none;"></iframe>
            <form
              action="attklstformupldproc.php"
              method="post"
              target="fuh1"
              enctype="multipart/form-data">
                <table border="2" cellpadding="3" frame="void" style="color: red; width:100%;">
                    <tr>
                        <td>Priority:</td>
                        <td>Pirate: <span id="Pirreq"></span></td>
                        <td>Level:</td>
                        <td>Known Fleet Level:</td>
                        <td>X:</td>
                        <td>Y:</td>
                    </tr>
                    <tr>
                        <td>
                            <select id="Priority" class="atklf" name="Priority">
                                <option value="1">1</option>
                                <option value="2">2</option>
                                <option value="3">3</option>
                                <option value="4">4</option>
                                <option value="5">5</option>
                                <option value="6">6</option>
                                <option value="7">7</option>
                                <option value="8">8</option>
                                <option value="9">9</option>
                                <option value="10">10</option>
                            </select>
                        </td>
                        <td><input id="Pirate" class="atklf" name="Pirate" type="text" size="17" /></td>
                        <td><input id="Level" class="atklf" name="Level" type="text" size="4" /></td>
                        <td><input id="Fleet_Level" class="atklf" name="Fleet_Level" type="text" size="4" /></td>
                        <td><input id="XCoord" class="atklf" name="XCoord" type="text" size="5" /></td>
                        <td><input id="YCoord" class="atklf" name="YCoord" type="text" size="5" /></td>
                    </tr>
                    <tr>
                        <td>Outpost Level:</td>
                        <td>Known Wall Level:</td>
                        <td>Known Turret Level:</td>
                        <td colspan="2">Turret Types:</td>
                        <td>Group: <span id="Grpreq"></span></td>
                    </tr>
                    <tr>
                        <td><input id="Outpost_Level" class="atklf" name="Outpost_Level" type="text" size="4" /></td>
                        <td><input id="Knwn_wall_lvl" class="atklf" name="Knwn_wall_lvl" type="text" size="4" /></td>
                        <td><input id="Knwn_turr_lvl" class="atklf" name="Knwn_turr_lvl" type="text" size="4" /></td>
                        <td colspan="2" rowspan="2"><textarea id="Turret_Types" class="atklf" name="Turret_Types" rows="5" cols="16"></textarea></td>
                        <td rowspan="2">
                            <select id="Group" class="atklf" name="Group">
                                <option value="null">Pick a group</option>
                                <option value="General">General</option>
                                <option value="Sector 23">Sector 23</option>
                                <option value="Max Chaos">Max Chaos</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>Base Picture:</td>
                        <td colspan="2"><input id="Base_Picture" name="uploaded_bp" class="atklf" type="file" /></td>
                    </tr>
                    <tr>
                        <td colspan="6">Notes:</td>
                    </tr>
                    <tr>
                        <td rowspan="1" colspan="6"><textarea id="Notes" class="atklf" name="Notes" rows="7" cols="60"></textarea></td>
                    </tr>
                    <tr>
                        <td align="center"><input id="hlfsubmit" class="atklf" name="submit" value="Submit" type="submit" style="width: 90px;" onClick="assignVars()" /></td>
                    </tr>
                    <input type="button" class="atklf" value="Reset debug" onClick="resetDebug()"/>
                    <input type="button" class="normal" value="Get File name" onClick="getFilename1()"/>
                </table>
            </form>
            <script type="text/javascript">

            function resetDebug() {
                document.getElementById("debug1").innerHTML = "";
            }

            function formFieldvalue(id) {
                return document.getElementById(id).value;
            }

            function getFilename1() {
                document.getElementById("debug1").innerHTML = formFieldvalue("Base_Picture");
            }

            Pri = "1";
            Pir = "null";
            Grp = "null";

            function assignVars () {
                Pri = document.getElementById("Priority").options[document.getElementById("Priority").selectedIndex].value;
                Pir = encodeURIComponent(formFieldvalue("Pirate"));
                if (formFieldvalue("Level")) {
                    Lvl = encodeURIComponent(formFieldvalue("Level"));
                }
                else {
                    Lvl = encodeURIComponent("?");
                }
                if (formFieldvalue("Fleet_Level")) {
                    Flv = encodeURIComponent(formFieldvalue("Fleet_Level"));
                }
                else {
                    Flv = encodeURIComponent("?");
                }
                if (formFieldvalue("XCoord")) {
                    XCd = encodeURIComponent(formFieldvalue("XCoord"));
                }
                else {
                    XCd = encodeURIComponent("?");
                }
                if (formFieldvalue("YCoord")) {
                    YCd = encodeURIComponent(formFieldvalue("YCoord"));
                }
                else {
                    YCd = encodeURIComponent("?");
                }
                if (formFieldvalue("Notes")) {
                    Nts = encodeURIComponent(formFieldvalue("Notes"));
                }
                else {
                    Nts = encodeURIComponent("?");
                }
                if (formFieldvalue("Outpost_Level")) {
                    Opl = encodeURIComponent(formFieldvalue("Outpost_Level"));
                }
                else {
                    Opl = encodeURIComponent("?");
                }
                if (formFieldvalue("Knwn_wall_lvl")) {
                    Kwl = encodeURIComponent(formFieldvalue("Knwn_wall_lvl"));
                }
                else {
                    Kwl = encodeURIComponent("?");
                }
                if (formFieldvalue("Knwn_turr_lvl")) {
                    Ktl = encodeURIComponent(formFieldvalue("Knwn_turr_lvl"));
                }
                else {
                    Ktl = encodeURIComponent("?");
                }
                if (formFieldvalue("Turret_Types")) {
                    Tty = encodeURIComponent(formFieldvalue("Turret_Types"));
                }
                else {
                    Tty = encodeURIComponent("?");
                }
                Grp = encodeURIComponent(formFieldvalue("Group"));
                insertAttacktablerow();
                }

                if ( window.addEventListener ) {
                    window.addEventListener( "load", insertAttacktablerow, false );
                }
                else if ( window.attachEvent ) {
                    window.attachEvent( "onload", insertAttacktablerow );
                }
                function insertAttacktablerow() {
                    if (Pir != "null" && Grp != "null") {
                        document.getElementById("Pirreq").innerHTML = "";
                        if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
                            xmlhttp=new XMLHttpRequest();
                        }
                        else { // code for IE6, IE5
                            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        xmlhttp.onreadystatechange=function() {
                            if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                                //updateAttacktable();
                                document.getElementById("debug1").innerHTML=xmlhttp.responseText;
                            }
                        }
                        xmlhttp.open("GET","/attacklist/attklstformproc.php?Pri=" + Pri + "&Pir=" + Pir + "&Lvl=" + Lvl + "&Flv=" + Flv + "&XCd=" + XCd + "&YCd=" + YCd + "&Nts=" + Nts + "&Opl=" + Opl + "&Kwl=" + Kwl + "&Ktl=" + Ktl + "&Tty=" + Tty + "&Grp=" + Grp + "&data=' . $data . '",true);
                        xmlhttp.setRequestHeader("X-Requested-With", "XMLHttpRequest");
                        xmlhttp.send();
                        document.forms[0].reset();
                    }
                    else if (Pir == "null") {
                        document.getElementById("Pirreq").innerHTML = "(<b>required</b>)";
                        document.getElementById("Pirreq").style.color = "red";
                    }
                    else if (Grp == "null") {
                        document.getElementById("Grpreq").innerHTML = "(<b>required</b>)";
                        document.getElementById("Grpreq").style.color = "red";
                    }
                }

            </script>
            <span id="debug1"></span>';

        }
        else
        {
            echo 'Restricted access.';
        }
  • 写回答

1条回答 默认 最新

  • dsa45132 2011-06-03 07:45
    关注

    OK, so I removed my last answer because I finally took the time to execute your code. As you have it, it works for me.

    Here's what I suggest you do. Remove your HTML and JavaScript and place them in a stand alone html file and load it in your browser. Add the necessary tags to make it complete. (Also, you're missing a "body" tag, not that this is the source of your problem.)

    Then test it. If it works, then your problem is coming from somewhere else not in the code you provided. Do you have header and footer code somewhere?

    If it doesn't work, start removing HTML and JavaScript in portions until it does work. Use this to isolate the cause of your bug.

    Good luck.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。