Solved

Form in asp page on load

Posted on 2001-06-27
17
195 Views
Last Modified: 2008-03-06
Hi.

Is there any way for me to, like, display a message when an asp page is loaded,and then something else when the user selects something from a drop down box??All help appreciated!

Thanks.
0
Comment
Question by:segafreak
  • 8
  • 6
  • 3
17 Comments
 
LVL 7

Expert Comment

by:weesiong
ID: 6233759
segafreak,

I no sure this is what you want

<%
Response.Buffer = True

'your script.....
%>
<script>
alert('i am message')
</script>
<%
Response.Flush

'continue your script.......
%>

Regards,
Wee Siong
0
 

Author Comment

by:segafreak
ID: 6233761
err,i mean writing a message to the page when the page first loads,something like "Please select a value".the message will be replaced by something from the db once the user selects value from the drop-down box and clicks on submit
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6233763
segfreak,

Ok, try this:

<%
'Your db connection
'Get the message you want put in message
%>
<script>
alert('<%=Rs("message")%>')
</script>
.
.
.

Regards,
Wee Siong
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233764
Try this

<html>

<head>
<script language="JavaScript">
<!--
function fun1()
{
     alert(document.frmMain.selMain[document.frmMain.selMain.selectedIndex].value + " selected");
}
//-->
</script>
</head>

<body onLoad="alert('Page Loaded')">
<form name="frmMain">
<select name="selMain" onChange="fun1()">
<option selected value="first">first
<option value="second">second
</select>
</form>
</body>

</html>

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233766
Oops!! Posted my above comment without refreshing this page. It is not you wanted.

hongjun
0
 
LVL 33

Accepted Solution

by:
hongjun earned 15 total points
ID: 6233775
Are you submitting to the same page or to another page? I assume you are using method="post". If you are using "GET" use Request.QueryString instead of Request.Form in the below code.


If another page,
Try this and place it at the top of the code page.

<%@language=VBScript%>

<%
if request.form("your_select_name") = "" then
    response.write "Please select a value<br>Click back to go back"
else
    response.write request.form("your_select_name") & " selected"
end if
%>


If same page,
Try this and place it at the top of the code page.

<%@language=VBScript%>

<%
if request.form("your_select_name") = "" then
    response.write "Please select a value"
else
    response.write request.form("your_select_name") & " selected"
end if
%>

hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233776
I think you are trying to do something like validation aren't you? Perhaps you can do client side validation using JavaScript.

hongjun
0
 

Author Comment

by:segafreak
ID: 6233784
erm,let me post the whole code...the thing is that i want a sentence to appear on the page(without using alert).that sentence will be replaced by tables pulled from the db once the user selects any non-default value from the drop down box and clicks submit...

<%@ Language=VBScript %>
<% Option Explicit %>
<% Response.Buffer = true %>

<%'enables database connection%>
<!--#include file="DBConnection.asp"-->

<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Course Outlines & Information</title>
</head>

<body bgcolor="#337066">

<p align="center">&nbsp;</p>
<p align="center"><font size="5" color="#FFFFFF">Course Outlines &amp; Information</font></p>
<hr size=1 width="50%">
<div align="center">
<%
      Dim SQL_b, rs1, MyConn
     
      OpenConnection MyConn
     Set rs1=Server.CreateObject("ADODB.recordset")
     SQL_b = " select distinct batch from moduleInfo "
     rs1.Open SQL_b,MyConn
     
%>
<form name = "batchName" action="g_courseOutlinesInfo.asp" method="POST">
<select name="batchCode">
<option selected value="selBatch">Select Batch</option>
<%
     Do Until rs1.EOF
%>
<option value="<%=rs1.fields("batch")%>"><%=rs1.fields("batch")%></option>
<%
     rs1.movenext
     Loop
     rs1.Close
     Set rs1 = Nothing
%>
</select>
<br>
<%Response.write "<p>Please select a batch</p>" %>
<p><br>
<a href="javascript:document.batchName.submit();"><img name="image1" border="0" src="images/view.gif"></a>
<%
     Dim batchCode, SQL_b1, rs2, MyConn1,course
     batchCode = Request.form("batchCode")
%>
<%
     If Request.form("batchCode") = "selBatch" then
%>
     <p align = "center">Please select a batch</p>

     <%Else%>

     <p align="center"><b><u><%=batchCode%></b></u></p>

//an eg of the table to replace the initial onload message    
<table width="631">
     
//this line shows up once the table is loaded...i want it to load only when the user selects something and submits...
<tr><td width="305" align="center"><u>Year One Semester One Core Modules</u></td><td width="4"></td><td width="302"></td></tr>
     <%
          OpenConnection MyConn1
          Set rs2=Server.CreateObject("ADODB.recordset")
          SQL_b1 = " select * from moduleInfo where batch = '"&batchCode&"' and year = '1' and semester = '1' "
          rs2.Open SQL_b1,MyConn1
          Do Until rs2.EOF
     %>
     <tr><td width="305" align="center"><%=rs2.fields("moduleCode")%></td><td width="4">:</td><td width="302"><%=rs2.fields("moduleName")%></td></tr>
     <%
          rs2.movenext
          loop
          rs2.Close
          Set rs2 = Nothing
     %>
</table>
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:segafreak
ID: 6233791
oops I mean,

//this line shows up once the form is loaded...i want it to load only when the user selects something
and submits...
<tr><td width="305" align="center"><u>Year One Semester One Core Modules</u></td><td width="4"></td><td
width="302"></td></tr>
    <%
         OpenConnection MyConn1
         Set rs2=Server.CreateObject("ADODB.recordset")
         SQL_b1 = " select * from moduleInfo where batch = '"&batchCode&"' and year = '1' and semester
= '1' "
         rs2.Open SQL_b1,MyConn1
         Do Until rs2.EOF
    %>
    <tr><td width="305" align="center"><%=rs2.fields("moduleCode")%></td><td width="4">:</td><td width="302"><%=rs2.fields("moduleName")%></td></tr>
    <%
         rs2.movenext
         loop
         rs2.Close
         Set rs2 = Nothing
    %>
</table>
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233798
form name = "batchName" action="g_courseOutlinesInfo.asp" method="POST">

Is g_courseOutlinesInfo.asp another page or same page?

hongjun
0
 

Author Comment

by:segafreak
ID: 6233799
same page
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233825
Try and replace the following statements

Replace
If Request.form("batchCode") = "selBatch" then

With
If Request.form("batchCode") = "selBatch" or Request.Form("barchCode") = "" then


I don't quite understand your this comment
//this line shows up once the form is loaded...i want it to load only when the user selects something

and submits...


Do you mean you want a alert message when user selected something and he submit? If yes then try this

<script language="JavaScript">
<!--
function do_function
{
    if ( document.batchName.batchCode.value != "selBatch" )
    {
        alert(document.batchName.batchCode[document.batchName.batchCode.selectedIndex].value + " selected")
    }
}
//-->
</script>

<form name = "batchName" action="g_courseOutlinesInfo.asp" method="POST" onSubmit="do_function();return true;">



hongjun
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233831
I made a mistake above. Replace with this

<script language="JavaScript">
<!--
function do_function()
{
   if ( document.batchName.batchCode.value != "selBatch" )
   {
       alert(document.batchName.batchCode[document.batchName.batchCode.selectedIndex].value + " selected")
   }
}
//-->
</script>

hongjun
0
 

Author Comment

by:segafreak
ID: 6233832
<%
     If Request.form("batchCode") = "selBatch" then
%>
     <p align = "center">Please select a batch</p>
     
     <%
          ElseIf Request.form("batchCode") = "" then
     %>
     <p align = "center">Please select a batch</p>

     <%Else%>
         //tables

this was what I tried and found to be successful.I modified it off this :

if request.form("your_select_name") = "" then
   response.write "Please select a value"

Thanks man.
0
 
LVL 33

Expert Comment

by:hongjun
ID: 6233834
You can actually do a client-side validation to make sure user selects something before it can be submitted. Then you won't even need a server-side validation.

<script language="JavaScript">
<!--
function do_function()
{
   if ( document.batchName.batchCode.value != "selBatch" )
       return true;
   else
       return false;
}
//-->
</script>

<form name = "batchName" action="g_courseOutlinesInfo.asp" method="POST" onSubmit="do_function()">

hongjun
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6233843
Singapore Poly Vs NanYang Poly

Me is what Poly :)
0
 

Author Comment

by:segafreak
ID: 6233858
huh???
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now