Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

Form in asp page on load

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
segafreak
Asked:
segafreak
  • 8
  • 6
  • 3
1 Solution
 
weesiongCommented:
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
 
segafreakAuthor Commented:
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
 
weesiongCommented:
segfreak,

Ok, try this:

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

Regards,
Wee Siong
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
hongjunCommented:
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
 
hongjunCommented:
Oops!! Posted my above comment without refreshing this page. It is not you wanted.

hongjun
0
 
hongjunCommented:
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
 
hongjunCommented:
I think you are trying to do something like validation aren't you? Perhaps you can do client side validation using JavaScript.

hongjun
0
 
segafreakAuthor Commented:
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
 
segafreakAuthor Commented:
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
 
hongjunCommented:
form name = "batchName" action="g_courseOutlinesInfo.asp" method="POST">

Is g_courseOutlinesInfo.asp another page or same page?

hongjun
0
 
segafreakAuthor Commented:
same page
0
 
hongjunCommented:
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
 
hongjunCommented:
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
 
segafreakAuthor Commented:
<%
     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
 
hongjunCommented:
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
 
weesiongCommented:
Singapore Poly Vs NanYang Poly

Me is what Poly :)
0
 
segafreakAuthor Commented:
huh???
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 8
  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now