dqu94359 2013-11-15 05:57
浏览 184

如何使用JS代码加载php文件

Since I am new to JS coding and web designing, I have a following doubt:

I have one html page which has onclick function for form text area. If text area remains empty and user clicks submit, it should display message to enter entry and if entry is right one the corresponding file should get open. I have if/else condition in JS file, which is giving appropriate message while text area remains empty but not loading file which I am mentioning when entry is not empty.

Below is the html snippet:

<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset=utf-8>
</head>
<body>
    <form name="drugform" action="#">
        <pre> Drug Name<input type="text" name="name1" value="" /></pre>
        </p>

        <input type="button" value="Enter" onclick='buttoncheck()' />
    </form>
    <script type="text/javascript" src="if-else-button.js"></script>
</body>
</html>

and JS code is:

function buttoncheck() {
    if (Boolean(document.drugform.name1.value)) {
        load(form1.php);
    } else {
        alert('Enter Drug name');
    }
}

How to load file with js code (mentioned in if condition)?

  • 写回答

3条回答 默认 最新

  • duanhai1455 2013-11-15 06:03
    关注
    var url = 'form1.php';
    window.location.href = url;
    

    Instead of load(form1.php), substitute the above code snippet!

    EDIT:

    If you want to load the file without actually redirecting to a new page, you can use jquery's .load() Check more about it here: http://api.jquery.com/load/

    评论

报告相同问题?