JavaScript无法通过点击执行

时间:2012-07-26 13:20:09

标签: javascript html onclick

我让这个JavaScript运行了一段时间,但我稍微改了一下,现在我无法让它运行。我在JavaScript中有一段时间的警报,我甚至无法触发它。这段代码上面有一些PHP,但它不应该干扰JavaScript。

<form action="http://go.gbpi.net/Outage/add-question/" method="post">
Question Name (A descriptive name for the question. Example: "Phone number", or "Pizza Size"): <br /><input type="text" name="questionName" />
<?php
echo("Category: <br /><select name=\"category\" id=\"category\">");
$mysqli = db_init();
$mysqli->next_result();
    $cats = $mysqli->query("call GetActiveCategories()");
    while ($row = $cats->fetch_assoc()){
        $categori = $row['Category_Text'];
        if(!($categori == $category)){
        echo("<option value = \"".$categori."\">".$categori."</option>");}
    }
echo("</select>");
?>
Question Text:<br /><input type="text" name="questionText" style='width:80%' />
Question Type:<br /><select name="myList" id="myList" onchange="selectType(); return false;">
<option value = "1">Yes or No</option>
<option value = "2">Multiple Choice</option>
<option value = "3">Multiple Select</option>
<option value = "4">Open Response</option>
    <option value = "5">Final Reply</option>
    <option value = "6">Summary</option>
</select>
<div id='regexes'>
type of input: <br /><select name="regex" id="regex">
<option value = "-1">any input</option>
<?php
    $mysqli->next_result();
    $regexes = $mysqli->query("call GetValidRegexes()");
    while($regex_row = $regexes->fetch_assoc()){
        $rid = $regex_row['Validation_ID'];
        $rname = $regex_row['Validation_Name'];
        echo("<option value = \"".$rid."\">".$rname."</option>");
    }
?>
</select>
</div>
<div id='buttons'></div>
<button id="adda" onclick="addAnswer(); return false;">add answer (max: 10)</button>
<input type="submit" value="add question" />
</form>
    <?php
            echo("<a href='./define-relationships/'>Define Question Relationships</a><br />");
    ?>
<script type="text/javascript">
    document.getElementById("adda").style.visibility="hidden";
</script>

<script type="text/javascript">
var answers = 0;
var inHTML = "";
function addAnswer()
{
if(answers < 10){
write = document.getElementById('buttons');
write.innerHTML = write.innerHTML + "answer: <input type=\"text\" name=\"answer" + answers + "\" /> <br>";
answers = answers + 1;}
}
</script>

<script type="text/javascript">
function selectType()
{
alert("HAHA I HATE YOU!");
var type=document.getElementById("myList").value;
if(type == "2" || type == "3"){
    document.getElementById("buttons").style.visibility="visible";
    document.getElementById("adda").style.visibility="visible";
    document.getElementById("regexes").style.visibility="hidden";
}
else if(type == "4"{
    document.getElementById("buttons").style.visibility="hidden";
    document.getElementById("adda").style.visibility="hidden";
    document.getElementById("regexes").style.visibility="visible";
}
else{
    document.getElementById("buttons").style.visibility="hidden";
    document.getElementById("adda").style.visibility="hidden";
    document.getElementById("regexes").style.visibility="hidden";
}}
</script>

1 个答案:

答案 0 :(得分:4)

如果没有jsfiddle,很难确定这是否是问题,但是在页面的最后一个脚本中有语法错误。

else if(type == "4"{

添加结束表,看看是否有帮助。