如何将readonly文本框值转换为javascript变量 [英] How to get the readonly textbox values into javascript variable

查看:69
本文介绍了如何将readonly文本框值转换为javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表格里面使用php我填充文本框字段并将其设置为readonly.now我想将readonly文本框值变为javascript中的变量并进行验证。加载文档后我试图存储值变成变量我得到空字符串。这样可以做到这一点。请帮帮我。谢谢。



<前lang =HTML> < div class = col-md-1 >
< div = form-group >
< label > CAPACITY < / label >
< 输入 type = text id = student1 名称 = student1 value = <?php echo $ venuecapacity1;?> readonly class = form-control >
< / div >
< / div >
< div class = col-md-1 >
< div class = form-group >
< label > 要分配< / label >
< 输入 < span class =code-attribute> type = text id = cpcty1 名称 = capacity1 class = form-control >
< 输入 type = hidden id = fld1 name = filled1 value = <?php echo $ capacity;?> readonly class = 表单控件 >
< / div >
< / div >
< / div >





我尝试过:



< pre> $( document )。ready(函数(){
debugger ;
var aloted = $( #fld1 )VAL();
var capacity = $( #cpcty1 )VAL();
var aloted2 = $( #fld2 )VAL();
var capacity2 = $( #cpcty2 )VAL();
var aloted3 = $( #fld3 )VAL();
var capacity3 = $( #cpcty3 )VAL();

$( #cpcty1)。change( function (){

alert(aloted);
alert(capacity);
});
});
< / script>

解决方案

venuecapacity1;?> readonly class = 表单控件 >
< / div >
< / div > ;
< div class = col-md-1 >
< div class = form-group >
< 标签 > 待分配< / label >
< input 类型 = text id = cpcty1 name = capacity1 class = 表单控件 >
< 输入 type = hidden id = fld1 名称 = filled1 value = <?php echo


capacity;?> readonly class = 表单控件 >
< / div >
< / div >
< / div >





我的尝试:



< pre lang =Javascript>< pre>


document )。ready(功能 (){
调试器;
var aloted =


i have a form inside that using php i am filling the textbox fields and set it to readonly.now i want to get the readonly textbox values into variables in javascript and do the validation.After loading the document i am trying to store values into variables i am getting empty string.is it possible to doing like this. please help me.Thanks in advance.

<div class="col-md-1">
						<div class="form-group">
						<label>CAPACITY</label>
						<input type="text" id="student1" name="student1" value="<?php echo $venuecapacity1;?>" readonly class="form-control">
						</div>
					</div>
					<div class="col-md-1">
						<div class="form-group">
						<label>TO BE ALLOTED</label>
						<input type="text" id="cpcty1" name="capacity1"   class="form-control">
						<input type="hidden" id="fld1" name="filled1" value="<?php echo $capacity;?>" readonly class="form-control">
						</div>
					</div>
				</div>



What I have tried:

<pre>$(document).ready(function(){
		debugger;
		var aloted=$("#fld1").val();
		var capacity=$("#cpcty1").val();
		var aloted2=$("#fld2").val();
		var capacity2=$("#cpcty2").val();
		var aloted3=$("#fld3").val();
		var capacity3=$("#cpcty3").val();

			$("#cpcty1").change(function(){

				alert(aloted);
				alert(capacity);
					});
				});
			</script>

解决方案

venuecapacity1;?>" readonly class="form-control"> </div> </div> <div class="col-md-1"> <div class="form-group"> <label>TO BE ALLOTED</label> <input type="text" id="cpcty1" name="capacity1" class="form-control"> <input type="hidden" id="fld1" name="filled1" value="<?php echo


capacity;?>" readonly class="form-control"> </div> </div> </div>



What I have tried:

<pre>


(document).ready(function(){ debugger; var aloted=


这篇关于如何将readonly文本框值转换为javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆