Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 31st, 2008, 08:56 PM
Authorized User
 
Join Date: Nov 2007
Location: , , .
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" />
Reply With Quote
  #2 (permalink)  
Old May 31st, 2008, 09:58 PM
Authorized User
 
Join Date: Nov 2007
Location: , , .
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>
Reply With Quote
  #3 (permalink)  
Old June 1st, 2008, 04:11 AM
Friend of Wrox
 
Join Date: Oct 2004
Location: delhi, delhi, India.
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
Reply With Quote
  #4 (permalink)  
Old June 4th, 2008, 10:20 PM
Authorized User
 
Join Date: Nov 2007
Location: , , .
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 05:23 AM.


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