[英]I am trying to get the value from sx:autocompleter in order to reset the value using javascript depending upon some conditions
[英]I am trying to get the value of a textbox in jsp using javascript.But i am unable to get.please give me some suggestion how to get it
/ 我正在嘗試使用javascript獲取jsp中文本框的值。但是我無法獲取。請給我一些建議。 /
<body>
<div class="container" id="q">
<section class="register" id="q1">
<h1>Register Book</h1>
<form name="BookRegistrationForm" action="./BookRegistrationController" method="post" onsubmit="return validate()">
<div class="reg_section personal_info">
<h3> BOOK TITLE :</h3><input type="text" name="bookTitle" id="bookTitle" value="">
/*to get the value i am writing this function.*/
<script type="text/javascript">
function validate()
{
var bookTitle=BookRegistrationForm.bookTitle.value;
alert(booktitle);}
如果您嘗試從dom中獲取值,則需要在腳本中添加document
關鍵字,
<script type="text/javascript">
function validate()
{
var bookTitle=document.forms["BookRegistrationForm"]["bookTitle"].value;
alert(booktitle);
}
</script>
你也可以這樣
var bookTitle= document.getElementById("bookTitle").value;
注意:
document.forms
將返回特定頁面內所有表單的集合。 document.forms["BookRegistrationForm"]
將從該集合中返回名稱為“ BookRegistrationForm ”的表單,因此您將通過上述表單訪問該字段。
希望這可以幫助
嘗試:
document.getElementById("bookTitle").value
嘗試使用document.getElementById()
;
<script type="text/javascript">
function validate(){
var bookTitle = document.getElementById("bookTitle").value;
alert(booktitle);
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.