Solved

Form in asp page on load

Posted on 2001-06-27
17
198 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
Can not run ASP pages Windows 10 Edge browser. 5 104
JQuery to parse xml string and get element by id 4 47
Connection to multiple databases 13 25
IIS components 2 14
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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