HTML code: The HTML code is dynamically created.
<li>
<div class="above">What do I like best?</div>
<div class="below">
<label>Answer:(1 words)</label>
<input id="question6" type="text" size="5"/>
<label id="sign6"/>
</div>
</li>
<li>
<div class="above">What city do I like?</div>
<div class="below">
<label>Answer:(1 words)</label>
<input id="question7" type="text" size="5"/>
<label id="sign7"/>
</div>
Jquery code:
function subjectivecheck(id){
alert(id);
var cost=(new Date().getTime() - start.getTime())/1000;
var value=$('#question'+id).val();
$.post("subjectivecheck.php?",{val:value, qid:id,time:cost, a_id:"<?php echo $announcementid; ?>"},function(xm){
switch(parseInt(xm)){
case 4:
{ $htm='Congrats,you have passed the test.';
$('#success').css({"color":"green"});
$('#success').text($htm);
return;
}
case 1:
{
$htm='V';
$('#sign'+id).css({"color":"green"});
$('#sign'+id).text($htm);
break;
}
case 0:{
$htm='X';
$('#sign'+id).css({"color":"red"});
$('#sign'+id).text($htm);
break;
}
case 3:{
$('#subjectivequestion').text('You have failed at this announcement.');
$('#choicequestions').text(" ");
}
}
});
}
var ajaxCallTimeoutID = null;
$('input[id^=question]').keyup(function(ev){
alert(this.id.substr(8));
if (ajaxCallTimeoutID != null)
clearTimeout(ajaxCallTimeoutID);
ajaxCallTimeoutID = setTimeout(subjectivecheck(id), 1000);
});
When I input something in question6
or
question7
,
the function $('input[id^=question]').keyup(function(ev) },does not work, there is no alert()
.Other jquery functions of this HTML file works fine.
Any idea?