将 p 值放入输入文本字段 2#

Put p value inside the input text field 2#

我在尝试在输入文本字段中移动值 p 时遇到小问题(第二个 table)。 我有 2 个不同的 table。首先 table 有按钮和 javascript。我已成功将值 "Chemendon" 和 "Morning" 传递给第二个 table,格式如下:

<p id="venue"></p>
<p id="session"></p>

在代码按钮下方,javascript 为第一个 table

<table class="table table-bordered">
<tbody>
<tr>
<td>
<input class="btn btn-avai btn-sm" type="button" onclick="addroom()" value="Available" />
</td>
  <script>
    function addroom() 
    { document.getElementById("venue").innerHTML = "Chemendon";
      document.getElementById("session").innerHTML = "Morning";
    }
  </script>
</tr>
</tbody>
</table>

第二个 table 只有输入文本字段和 p 值,我想将 p 值移动到输入文本字段中

<table class="table table-bordered">
<tbody>
<tr>
<td>
<input class="form-control" type="text" placeholder="Venue/Facility" size="1"/>
<p id="venue"></p>
</td>
<td>
<input class="form-control" type="text" placeholder="Session" size="1"/>
<p id="session"></p>
</td>
</tr>
</tbody>
</table>

我该怎么做?

注意。我之前已经问过这个问题,并且有 2 个人回答了我的问题。但这是行不通的。所以在这里我试着解释更多的细节。

谢谢,faizal。

当您知道如何使用段落元素的 ID 来赋值时,为什么不能尝试使用输入元素的 ID,

<input id="tvenue" class="form-control" type="text" placeholder="Venue/Facility" size="1"/>
<input id="tsession" class="form-control" type="text" placeholder="Session" size="1"/>

然后让您的 javascript 为您的输入元素赋值,

function addroom() 
{ document.getElementById("tvenue").value = "Chemendon";
  document.getElementById("tsession").value = "Morning";
}

只是基本的 javascript 东西。不是吗?还是我遗漏了你的问题?

请将具体的ID添加到您的输入框中,例如

<input class="form-control" type="text" placeholder="Venue/Facility" size="1" name="venue" id="venue_input" />
<input class="form-control" type="text" placeholder="Session" size="1" name="session" id="session_input" />

你可以使用下面的代码

<script>
function addroom() 
{ 
    document.getElementById("venue").innerHTML = "Chemendon";
    document.getElementById("session").innerHTML = "Morning";
    document.getElementById("venue_input").value = document.getElementById("venue").innerHTML;
    document.getElementById("session_input").value = document.getElementById("session").innerHTML;
}
</script>

你必须得到输入字段然后它的值document.getElementById("venueInput").value请查看这个代码笔

http://codepen.io/anon/pen/RWWRxw