文本框使用if-else语句、javascript使链接可见

文本框使用if-else语句、javascript使链接可见,javascript,validation,Javascript,Validation,是否有一种方法可以使链接在同一页面上可见,而不是在新页面上打开链接?例如,如果我在文本字段中写下“project”并按下submit按钮,则project.htm链接将在页面上可见;如果我在文本框中写下“under”,然后按submit按钮,则understruction.htm链接将可见 <script Language="JavaScript"> <!-- function Blank_TextField_Validator() {

是否有一种方法可以使链接在同一页面上可见,而不是在新页面上打开链接?例如,如果我在文本字段中写下“project”并按下submit按钮,则project.htm链接将在页面上可见;如果我在文本框中写下“under”,然后按submit按钮,则understruction.htm链接将可见

    <script Language="JavaScript">
    <!--
        function Blank_TextField_Validator() {
            // Check the value of the element named text_name from the form named text_form
            if (text_form.text_name.value == "") {
                // If null display and alert box
                alert("Please fill in the text field.");
                // Place the cursor on the field for revision
                text_form.text_name.focus();
                // return false to stop further processing
                return (false);
            }
           // If text_name is not null continue processing
           if (text_form.text_name.value == "project")
               window.open('project.htm');
           else if (text_form.text_name.value == "under")
               window.open('underconstruction.htm');
           else
               alert("Invalid keyword!");
           return (true);
        }
    -->
    </script>

不确定这是否是一个骗人的问题。。你就不能这么做吗

脚本

if (text_form.text_name.value == "project")
    document.getElementById('project_link').style.display = 'block';
else if (text_form.text_name.value == "under")
    document.getElementById('construction_link').style.display = 'block';
else
    alert("Invalid keyword!");
return (false);
标记

<a id='project_link' href='project.htm' style='display: none;'>project</a>
<a id='construction_link' href='underconstruction.htm' style='display: none;'>construction</a>


你能写出完整的代码吗,因为我不知道在哪里添加标记部分。@JavariaShah这将与你的其余标记(无论在哪里)一起。你是说在这里?它在这里不起作用。是的,正是我的意思。您还必须确保返回false,以便表单不会提交。请看我的更新上面(也修复了一个打字错误)。