JavaScript function not executing
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>
开发者_JAVA百科 </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.';
}
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.
精彩评论