Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 31st, 2008, 08:56 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default Displaying message on the form

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" />
 
Old May 31st, 2008, 09:58 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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 ?
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){
        document.forms['timeListForm'].elements['valCheckBox'].value = 'Please select something';
        //alert('please check a project');

    }
    else{
        alert('project checked');

    }
}
Code:
<input type="text" name="valCheckBox" border=0 size=100>
 
Old June 1st, 2008, 04:11 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 553
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via MSN to vinod_yadav1919 Send a message via Yahoo to vinod_yadav1919
Default

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
 
Old June 4th, 2008, 10:20 PM
Authorized User
 
Join Date: Nov 2007
Posts: 54
Thanks: 1
Thanked 0 Times in 0 Posts
Default

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.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Grid Not Displaying Error Message rojiin ASP.NET 2.0 Basics 0 October 22nd, 2007 05:13 AM
Displaying a completed message after the query has sibo32000 Excel VBA 1 February 19th, 2007 11:13 PM
Subreport not displaying no data message in main lic023 Access 0 March 15th, 2005 08:15 AM
Form Not Displaying owain Pro VB 6 10 July 10th, 2003 03:24 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.