Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将radiobutton值作为参数从一个html页面传递到另一个页面,并在下一个html页面上提取它_Javascript_Html - Fatal编程技术网

Javascript 将radiobutton值作为参数从一个html页面传递到另一个页面,并在下一个html页面上提取它

Javascript 将radiobutton值作为参数从一个html页面传递到另一个页面,并在下一个html页面上提取它,javascript,html,Javascript,Html,我是HTML新手。我写了下面的代码来选择其中一个选项。在选择其中一个radiobutton并单击submit按钮后,用户应该被重定向到考试页面,其中候选人类型来自URL中传递的radiobutton值,该值必须在下一页提取 有人能帮我在下一页传递值并提取它吗 <html> <head> <title>Online Examination Portal</title> <h1>Online Exam

我是HTML新手。我写了下面的代码来选择其中一个选项。在选择其中一个radiobutton并单击submit按钮后,用户应该被重定向到考试页面,其中候选人类型来自URL中传递的radiobutton值,该值必须在下一页提取

有人能帮我在下一页传递值并提取它吗

<html>
    <head>
        <title>Online Examination Portal</title>
        <h1>Online Examination</h1>
        <script type="text/javascript">
            function get_action(form) {
            form.action = document.querySelector('input[name = "candidateType"]:checked').value;
        }
        </script>
    </head>
    <body>
        <div>Select candidate type from below option:<br><br>
            <div>
                <input type="radio" name="candidateType" value="student">Student
                <br>
                <input type="radio" name="candidateType" value="professional">Professional  
                <br><br>
                <form action="ExamPage.html" method="get"><input type="submit" value="Submit" onclick="get_action(this);"></form>           
                <br><br>
                <form action="RegistrationPage.html" method=post name="form2"><input type="submit" value="Register"></form>
            </div>
        </div>
    </body>
</html>

在线考试门户
在线考试
函数get_动作(表单){
form.action=document.querySelector('input[name=“candidateType”]:checked')。值;
}
从下面的选项中选择候选类型:

学生
专业的




您可以使用cookie或
本地存储
,其中
本地存储
更容易实现,但需要最新的浏览器,用户可能出于隐私原因禁用cookie

Cookies

function setCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

// First Page
setCookie("myinputvalue", document.getElementsByName("candidateType")[0].value, 10);

// Second Page
getCookie("myinputvalue");
可能重复的
if (typeof(Storage) !== "undefined") {
  // First Page
  localStorage.setItem("myinputvalue", document.getElementsByName("candidateType")[0].value);
  // Second Page
  localStorage.getItem("myinputvalue");
} else {
  // Sorry! No Web Storage support..
  // Use the above cookie method.
}