?
Solved

Form in asp page on load

Posted on 2001-06-27
17
Medium Priority
?
203 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 60 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

718 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