Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms 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 February 27th, 2005, 05:58 AM
Authorized User
 
Join Date: Feb 2005
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kumarop
Default if condition is not working

Dear sir,
if loop is not working when i try to submit this through javascript code.Whereas it is working fine when i submit by giving type = "submit" on button.
why "If Request.Form("btnSubmit") <> "" Then" this loop is not working when i try to submit this form by javascript?

please help.

regards
om prakash


<%@ Language=VBScript %>
<HTML>
<HEAD>
<script>
function fn_submit()
{
  if (document.forms[0].txtName.value==null || document.forms[0].txtName.value=="" )
  {
  alert ("Name is empty");
  document.forms[0].txtName.focus();
  return false;
  }
    else if (document.forms[0].vendorcode.value==null || document.forms[0].vendorcode.value=="")
            {
            alert ("IFFCO Vendor Code is empty");
            document.forms[0].vendorcode.focus();
            return false;
            }
    else if (document.forms[0].txtemail.value==null || document.forms[0].txtemail.value=="")
            {
            alert ("email is empty");
            document.forms[0].txtemail.focus();
            return false;
            }
  else
  {
    document.forms[0].submit();
  }
}
</script>

<%

If Request.Form("btnSubmit") <> "" Then
  Dim UserName
  Dim UserMessage
  UserName = Request.Form("txtName")
  UserMessage = Request.Form("txtMessage")
  Dim Message
  Message = "Mail from the Web site" & vbCrlf & vbCrLf
  Message = Message & "User " & UserName & _
       " left the following message: " & vbCrLf
  Message = Message & UserMessage & vbCrLf & vbCrLf
  Const cdoSendUsingPort = 2

  ' something in loop in fact i am sending email from here
  ' Clean up variables.
  Set oMessage = Nothing
  Set oConfiguration = Nothing
  Set oFields = Nothing
  Response.Redirect("ThankYou.asp")
  End If

%>
</HEAD>

<BODY>
<form id="frmSendEmail" method="post" action="Sendemail.asp">
    <table border = "0" align ="top" cellspacing = 1 cellpadding = 1>
    <tr><td ALIGN=left colspan = 2><h3>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;&nbsp;&nbsp;
      Password Reset Requsition From</h3></td></tr>
    <tr bgcolor="#eeeeee">
         <td ALIGN=left><STRONG>Your
      Name:</STRONG>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
      &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<input name="txtName" id="txtName" style="WIDTH: 206px; HEIGHT: 22px" size=26
     > * </td><tr>
    <tr bgcolor="#eeeeee">
         <td ALIGN=left><STRONG>Your Vendor Code:</STRONG>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; &nbsp;<INPUT id=vendorcode name=vendorcode
      style="WIDTH: 83px; HEIGHT: 22px" size=10> *</td></tr>
    <tr bgcolor="#eeeeee">
         <td ALIGN=left><STRONG>Your Company
      email:</STRONG> &nbsp;&nbsp;&nbsp;<INPUT id=txtemail style="LEFT: 95px; WIDTH: 208px; TOP: 40px; HEIGHT: 22px" size=25
                         name=txtemail> *</td>
        <td ALIGN=left>(On Which you wanted to receive your password)</td></tr>
    <tr bgcolor="#eeeeee">
        <td ALIGN=left><STRONG>Your message:</STRONG> </td></tr>
    <tr bgcolor="#eeeeee">
        <td align = left> <TEXTAREA id=txtMessage name=txtMessage rows=10 cols=40></TEXTAREA></td></tr><br>
    <tr bgcolor="#eeeeee"><td><input type="button" name="btnSubmit" id="btnSubmit"
          value="Send Message" onclick="fn_submit()"> </td></tr>

</table>
</form>
</BODY>
</HTML>






om prakash kumar
__________________
om prakash kumar
 
Old February 27th, 2005, 06:10 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi om prakash,

That's because the button is not submitted with the form when you submit it through code; the button will only be passed to the server when you actually click it.

To work around this, add a hidden form field to your form and check for that field:
Code:
<form ...>
  <input type="hidden" value="True" name="IsSubmitted" />
  ... 
</form>
Then in your ASP code use this:
Code:
If Request.Form("IsSubmitted") <> "" Then

End If
HtH,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
While typing this post, I was listening to: Photograph by Weezer (From the album: Green Album) What's This?
 
Old February 27th, 2005, 08:49 AM
Authorized User
 
Join Date: Feb 2005
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to kumarop
Default

Thanks Imar,
it is working now.Thnaks a lot for concept.

om prakash kumar





Similar Threads
Thread Thread Starter Forum Replies Last Post
or condition kgoldvas XSLT 1 July 31st, 2007 03:44 AM
Help with writing if condition jendys XSLT 9 April 30th, 2007 04:02 AM
where condition...? mnr555 Crystal Reports 0 June 18th, 2006 05:32 PM
if then else condition mateenmohd Classic ASP Basics 0 April 16th, 2005 07:08 AM
Condition mateenmohd SQL Server 2000 6 May 6th, 2004 03:49 AM





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