我尝试在内部表单上收集一些值( 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>