User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,695 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,165 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1558 | Replies: 5
Reply
Join Date: Oct 2006
Posts: 15
Reputation: shaun09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
shaun09 shaun09 is offline Offline
Newbie Poster

Validation script cant seem to work

  #1  
Oct 27th, 2006
I'm trying to validate some fields in my form but can't get it to work. I think it's because of the submit button code. Could someone please help identify the problem?

<script language="JavaScript">
function validate_form ( )
{
if ( document.leaveform.dc1.value == "" )
        {
                alert ( "Please select start date" );
                valid = false;
                return valid;
 
       }
}    


<input name="b1" type="button" value="Submit Without Preview"
ONCLICK ="this.form.action ='fastsaveregistrationdetails.jsp';this.form.submit()">
Last edited by tgreer : Oct 27th, 2006 at 3:33 pm. Reason: Added code tags. User posted from a keyboard with no apostrophe key - added them.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: Utrecht, The Netherlands
Posts: 9
Reputation: BudBrocken is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
BudBrocken BudBrocken is offline Offline
Newbie Poster

Re: Validation script cant seem to work

  #2  
Oct 27th, 2006
try putting it in the form's onsubmit event, like this:
<form onsubmit="return validate_form()">
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Solution Re: Validation script cant seem to work

  #3  
Oct 27th, 2006
Hi,

try this Code its working

code given by BudBrocken is right


</head>
<script language="JavaScript">
function validate_form ( )
{
if ( document.leaveform.dc1.value == "" )
{
alert ( "Please select start date" );
valid = false;
return valid;
//document.leaveform.submit();
}
}
</script>


<body>

<form action="fastsaveregistrationdetails.jsp" method="post" name="leaveform" onsubmit="return validate_form()">
<input name="dc1" type="text" />
<input name="b1" type="submit" value="Submit Without Preview">
</form>
</body>

Best regards,
Rahul
Last edited by katarey : Oct 27th, 2006 at 3:24 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Oct 2006
Posts: 15
Reputation: shaun09 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
shaun09 shaun09 is offline Offline
Newbie Poster

Re: Validation script cant seem to work

  #4  
Nov 12th, 2006
The problem is i cant change the following code as i'm using it for having multiple submit buttons on one form. Please advice on how i can run the validation script based on this. Thank you..

[html]<input name="b1" type="button" value="Submit Without Preview"
ONCLICK ="this.form.action ='fastsaveregistrationdetails.jsp';this.form.submit()">[/html]
Last edited by tgreer : Nov 14th, 2006 at 3:18 pm. Reason: Added code tags.
Reply With Quote  
Join Date: Oct 2006
Location: India
Posts: 1,289
Reputation: vishesh is on a distinguished road 
Rep Power: 4
Solved Threads: 32
vishesh's Avatar
vishesh vishesh is offline Offline
Nearly a Posting Virtuoso

Re: Validation script cant seem to work

  #5  
Nov 12th, 2006
You could use if decision with the values returned by the validate_form().
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 143
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 15
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Help Re: Validation script cant seem to work

  #6  
Nov 14th, 2006
Actually I am not getting your Question, but try this code

<script language="JavaScript">
function validate_form ( )
{

if ( document.leaveform.dc1.value == "" )
{
alert ( "Please select start date" );
valid = false;
return valid;
document.leaveform.submit();
}
}
</script>
<body>
<form  method="post" name="leaveform" >
  <input name="dc1" type="text" />
    <input name="b1" type="submit" value="Submit Without Preview" onclick="this.form.action ='fastsaveregistrationdetails.jsp';return validate_form()">

</form>
</body>

feel free to ask or clearify the quetion

Regards,
Rahul
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 2:38 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC