I have a php page that has certain javascript functions and html code. The page form contains display of certain data extracted from the database through php, and is displayed as html checkboxes in a table. After the table I have a drop down list followed by a submit button. A user select options from the drop down (copy, delete, save etc) and based on the user selection from the check box, performs other tasks, once the submit button is clicked.
My problem: there is no way of checking that the check boxes has been checked or not. In order to do that, I am trying to write a javascript function that checks for the checked boxes and displays the message such as "please select a check box if none has been selected". I have been able to display an alert message, suggesting that a check box needs to be selected to proceed further.
What is left: I want a message to be displayed instead of the alert box, and that too on the same page beside the submit button. I have tried using document.write but it is displaying on a new page and not the same page. Is there anyway of embedding html into javascript function to display that? or anyone can suggest something here ?
I have listed the javascript function and my submit button code to illustrate that in the code language. I would greatly appreciate any help in this matter, Thanks.
Code:
function testCall(){
var flag = false ;
for (var i = 0; i < document.forms['timeListForm'].elements.length ; i ++){
if(document.forms['timeListForm'].elements[i].checked == true){
flag = true ;
break ;
}
}
if (flag == false){
alert('please check a project');
}
else{
alert('project checked');
}
}
and my submit button:
Code:
<input type="button" onClick="testCall();" name="btnActions" value="Go" />