Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Step by step form validation needed-Please check this code!!
Old 03-16-2006, 10:17 AM Step by step form validation needed-Please check this code!!
Junior Talker

Posts: 3
Trades: 0
Code:
 
<html>
<title>Date Formatting Application </title>
<script language="JavaScript">
<!--

function form_checker()
{

var radio_choice = false;
for (counter = 0; counter < form.radio_button.length; counter++)
{
if (form.radio_button[counter].checked)
radio_choice = true; 
}


if (document.form.input_date.value == "") 
{
alert("You must enter a date.")

}

if (document.form.Format_string.value == "") 
{
alert("- You must select both formatting string choices \n  - Invalid option - 1 | 2 | 3 only are allowed.")
}


if (!radio_choice)
{
 alert("No date format clicked.")

return (false);
}
return (true);
}



-->
</script>



<form method="post" action="output.asp" onsubmit="return form_checker()" name="form">

<b>Enter a date:
<br>

<input type="text" name="input_date">e.g. 1/2/2006 1:1:1 PM
<br>
<br>

Select format string (Choices 1: for mm/dd/yyyy  2 for dd/mm/yyyy  3 for dd/mm/yy):
<br>


<select name="Format_string" SIZE="1">
<option value="">Select format string</option>
<option value="1"> 1 </option> 
<option value="2"> 2 </option> 
<option value="3"> 3 </option> 

</select>



<br>
<br>
<br>

Click any date format string:

<br>

<input type="radio" value="General Date" name="radio_button">    General Date (mm/dd/yyyy hh:mm:ss AM/PM)        <br>

<input type="radio" value="Short Date" name="radio_button">    Short Date (dd/mm/yy)                           <br>

<input type="radio" value="Long Date" name="radio_button">    Long Date (day of week, month Name day, year)   <br>

<br>
<input type="submit" value="Submit">

</b>
</form>

</body>
</html>
Above code I have written to validate the form. But the problem is that, all the field are checked once and then page forward itself (in Internet Explorer). I want this problem to be solve. If one field is error then message should be displayed and control remain there, unless all field is completed then only form be submitted.

The live code is at www.erealmedia.com/assignment.asp

Last edited by askme; 03-16-2006 at 10:18 AM..
askme is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-18-2006, 02:28 AM Re: Step by step form validation needed-Please check this code!!
Super Talker

Posts: 144
Trades: 0
if you explain a little better what you are doing, perhaps I could have written the regular expressions for you to validate the date format, but I'm not sure with the different selection and radio button options...

anyways, this should work for what you explained. I fixed up your HTML just a little bit and changed up your function.

Code:
<html>
<head>
  <title>Date Formatting Application</title>
  <script language="JavaScript">
    <!--
      function form_checker(formNode) {
        var i, radio_choice = false;
        if (formNode.input_date.value == "") {
          alert("You must enter a date.");
          formNode.input_date.focus();
          return(false);
        }
        if (formNode.format_string.selectedIndex <= 0)  {
          alert("You must select a formatting string option \n  - Invalid option - 1 | 2 | 3 only are allowed.");
          formNode.format_string.focus();
          return(false);
        }
        for (i = 0; i < formNode.radio_button.length; i++) {
          if (formNode.radio_button[i].checked) {
            radio_choice = true;
            break;
          }
        }
        if (!radio_choice) {
         alert("No date format clicked.")
         return(false);
        }
        return(true);
      }
    -->
  </script>
</head>
<body bgcolor="#FFFFFF">
<form method="post" action="output.asp" name="my_form" onsubmit="return(form_checker(this))">
<b>Enter a date:
<br>
<input type="text" name="input_date">e.g. 1/2/2006 1:1:1 PM <br><br>
Select format string (Choices 1: for mm/dd/yyyy  2 for dd/mm/yyyy  3 for dd/mm/yy):
<br>
<select name="format_string" SIZE="1">
  <option value="">Select format string</option>
  <option value="1"> 1 </option>
  <option value="2"> 2 </option>
  <option value="3"> 3 </option>
</select>
<br><br><br>
Click any date format string:<br>
<input type="radio" value="General Date" name="radio_button">    General Date (mm/dd/yyyy hh:mm:ss AM/PM)        <br>
<input type="radio" value="Short Date" name="radio_button">    Short Date (dd/mm/yy)                           <br>
<input type="radio" value="Long Date" name="radio_button">    Long Date (day of week, month Name day, year)   <br>
<br>
<input type="submit" value="Submit" name="btnSubmit">
</b>
</form>
</body>
</html>
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Old 03-30-2006, 06:04 AM Re: Step by step form validation needed-Please check this code!!
Junior Talker

Posts: 3
Trades: 0
I copied these codes, saved as an html page. When I tried to click submit button, it is not working, Javascript pop up box sholud appear telling me, please fill the empty text box.
askme is offline
Reply With Quote
View Public Profile
 
Old 03-30-2006, 06:07 AM Re: Step by step form validation needed-Please check this code!!
Super Talker

Posts: 144
Trades: 0
http://www.createvibe.com/open_sourc...alidation.html
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Old 03-31-2006, 07:25 AM Re: Step by step form validation needed-Please check this code!!
Junior Talker

Posts: 3
Trades: 0
Thanks-----createvibe.com
askme is offline
Reply With Quote
View Public Profile
 
Old 03-31-2006, 07:46 AM Re: Step by step form validation needed-Please check this code!!
Super Talker

Posts: 144
Trades: 0
no problem, buddy
__________________
create.vibe

Please login or register to view this content. Registration is FREE
createvibe.com is offline
Reply With Quote
View Public Profile Visit createvibe.com's homepage!
 
Reply     « Reply to Step by step form validation needed-Please check this code!!
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.79705 seconds with 12 queries