Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

verify text field is not empty before submit

Posted on 2008-09-30
3
Medium Priority
?
1,504 Views
Last Modified: 2010-04-21
Hi,

I have a text field
<input type="text" name="date" id="data" size="12" readonly onclick="popupcalendar('mydata')" />

which when clicked pops up a calendar. Below that is a submit button..

<input type="submit" name="submit" value="" class="submit"/>

If I click submit and the user has selected a date then no problem...if I click submit with no date is selected then it throws an error.

How can I verify that the user has selected a date (or the textbox is not empty) before going ahead with the submit....

All I'm really looking for is a simple alert box saying "Please select a date"


Thanks,

0
Comment
Question by:thegunner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 4

Accepted Solution

by:
sijishJohn earned 200 total points
ID: 22604199
Add this script to your page

<script language="javascript" type="text/javascript">
    function ValidateDate()
    {
        if(document.getElementById('data').value == "")
        {
            alert('Please select a date');
            return false;
        }
    }
   
    </script>


and call it in onclick event of the button...

<input type="submit" name="submit" value="" class="submit" onclick="return ValidateDate()"/>
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 22604572
You can also submit after validating the input,


<script language="javascript" type="text/javascript">
    function ValidateDate()
    {
        if(document.formname.data.value == "")
        {
            alert('Please select a date');
            return false;
        }
		
		document.frmname.submit();
		return true;
    }
   
    </script>
 
 
<input type="button" name="submit" value="Save" class="submit" onclick="return ValidateDate()"/>

Open in new window

0
 

Author Closing Comment

by:thegunner
ID: 31501504
cheers...
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question