show hide div javascript将值从表单传递到另一个表单

时间:2017-10-03 17:06:05

标签: javascript php

我尝试在内部表单上收集一些值( mydiv ),将这些值传递给下面的表格mydiv2)< / strong>,隐藏mydiv,并在用户提交后显示mydiv2

问题是我使用onload event来填充输入字段&#34; displayName&#34; mydiv2中的表单,这使得无法使用其他方法来交换div ...

这可能吗?有没有其他方法可以做到这一点?

到目前为止,这是我的代码:

<div id="mydiv">
<!-- div to show by default and hide after users submit the form below -->
<form id="loginForm" method="POST">
 <input type="text" name="j_name" value="" placeholder="name here"/>
 <input type="submit" onclick="" value="submit"/>
</form>
</div>

<div id="mydiv2">
<!-- div to hide by default and show after users submit the form above -->
<form id="2Form">
 <input type="text" name="displayName" value="" placeholder="name here"/>
 <input type="submit" onclick="" value="submit"/>
</form>
</div>

<?php $the_name = $_POST['j_name'];?>

<script>
// Wait for the DOM to finish loading.
var previousOnload = window.onload;
window.onload = function () {

    // Execute any other `onload` function which may have been bound previously.
    if (typeof previousOnload === 'function') {
        previousOnload();
    }

document.getElementsByName('displayName')[0].value = "<?php echo $the_name; ?>";

};
</script>

0 个答案:

没有答案