[英]Can anyone help and tell me why do i get a null value in the function
Heres the Code这是代码
This is the Script这是脚本
<script>
$(document).ready(function(){
$('#done_edit').click(function(){
var name= document.getElementById('first_name').value;
alert(name);
});
});
This is for the form这是为了表格
<form id="passedit" class="submit">
<label>First Name:</label><input type="text" name="first_name" class="form-control" value="<?php echo $row['name'];?>" />
<button type="submit" class="btn btn-info" id="done_edit" >DONE<span class="glyphicon glyphicon-check"></span></button>
Because you don't have an element with an Id set to first_name因为您没有将 Id 设置为 first_name 的元素
you should have something like你应该有类似的东西
<input type="text" id="first_name" class="form-control">
var name= document.getElementById('first_name'); var name= document.getElementById('first_name'); You should have an element wich has the ID as "firstname".
您应该有一个 ID 为“名字”的元素。 For example,`
例如,`
<input type="text" id="first_name" value="Type your text here"/>
Then you'll get the output as an object.<input type="text" id="first_name" value="Type your text here"/>
然后你会得到一个对象的输出。
If you rewrite the mentioned line as follows,如果您按如下方式重写上述行,
var name= document.getElementById('first_name').value;
You'll get "Type your text here" in your alert box.您将在警报框中看到“在此处输入您的文字”。 ie: Change the attribute name to id in your textbox.
即:在文本框中将属性名称更改为 id。
Now you have in the alert the value of the element.现在您在警报中有元素的值。
HTML HTML
<form id="passedit" class="submit">
<label>ID Number:</label><input id="first_name" type="text"
name="id_number" class="form-control" value="<?php echo
$row['name'];?>" />
<button type=
JS JS
$(document).ready(function(){
$('#done_edit').click(function(){
var name= document.getElementById('first_name').value;
alert(name);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.