Javascript var返回Undefined

时间:2016-05-22 13:46:16

标签: javascript php undefined

在html输入中,我从mysql数据库中获取价值......但是当我尝试将此值用作javascript中的var时,我将其视为未定义...

<tr >
<td>Advt Heading :</td>
<td>
<input type="hidden" name="idnew" id="idnew" value="<?=$member_data['id']?>"> //retrieved from mysql database 

<input type="text" name="advt_headingnew" id="advt_headingnew" value="<?=stripslashes($member_data['advt_heading']);?>" /> //retrieved from mysql database ...**I want to edit its previus retreived value...and update database**

<input name="submit" type="button" id="submit" value="Update" />

</td>
</tr>



<script src="http://code.jquery.com/jquery.min.js"></script>  
<script>
$(document).ready(function () { 
$('#submit').click(function(){
var advt_headingnew = $("#advt_headingnew").val();
var idnew = $("#idnew").val();
alert(advt_headingnew);  //****Getting UNDEFINED
alert(idnew); //****Getting UNDEFINED

$.ajax({
     type:'POST',
     url:'update-advt-heading.php',
     data: "advt_headingnew="+advt_headingnew+"&idnew="+idnew,

     success:function( msg ) {
     alert( "Data Saved: " + msg );
    }

 });
});
});
</script>

enter image description here

我从mysql数据库获取HTML输入中的值...但是这些值没有在javascript中传递为var ...并且返回为Undefined .......

1 个答案:

答案 0 :(得分:1)

我已经改变了

Found = in conditional, should be == at ./15.pl line 6. Useless use of
private variable in void context at ./15.pl line 18. Useless use of
private variable in void context at ./15.pl line 22. Unsuccessful stat
on filename containing newline at ./15.pl line 16, <$fh> line 2.
Unsuccessful stat on filename containing newline at ./15.pl line 16,
<$fh> line 2. Varmış böyle dizin Unsuccessful stat on filename
containing newline at ./15.pl line 16, <$fh> line 2. Unsuccessful stat
on filename containing newline at ./15.pl line 16, <$fh> line 2.
Varmış böyle dizin

var advt_headingnew = $("#advt_headingnew").val();
var idnew = $("#idnew").val();

现在正在工作....

谢谢大家的合作......

 var advt_headingnew = document.getElementsByName("advt_headingnew")[0].value;
 var idnew = document.getElementsByName("idnew")[0].value;