|
Subject:
|
Displaying message on the form
|
|
Posted By:
|
nasirmunir
|
Post Date:
|
5/31/2008 8:56:56 PM
|
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.
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:
<input type="button" onClick="testCall();" name="btnActions" value="Go" />
|
|
Reply By:
|
nasirmunir
|
Reply Date:
|
5/31/2008 9:58:46 PM
|
okay some advancement: now I can display the message in a text box instead of an alert message. However, another problem: I don't want it to be displayed as a text box, it should be hidden. Only in case of helping message display it should be visible. Can I get some help here ?
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){
document.forms['timeListForm'].elements['valCheckBox'].value = 'Please select something';
//alert('please check a project');
}
else{
alert('project checked');
}
}
<input type="text" name="valCheckBox" border=0 size=100>
|
|
Reply By:
|
vinod_yadav1919
|
Reply Date:
|
6/1/2008 4:11:43 AM
|
Hii nasirmunir!!
You can also add div tag with style visibility on the fly.. you can turnon/off the visibility and message on it, it depends on ur requirement and the implementations.
Cheers :)
vinod
|
|
Reply By:
|
nasirmunir
|
Reply Date:
|
6/4/2008 10:20:16 PM
|
Thanks Vinod, that solved the problem :) That was exactly what I was looking for. For others, div tag provides number of attributes which you can use for your need. I used, class, display and visibility and that worked perfect for me.
|