Advertisement

10.03.2005 at 03:03AM PDT, ID: 21581628
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.4

Populating a list Box at runtime

Asked by bizdata in JavaScript

Tags: , , ,

need a way to make the page do a refresh instead of a submit to populate the categorylist form element cos at this moment of the code on select of the main directory it inserts into the database which is not suppose to do so
even  in the form tag i set the MM_insert to null and initialized it in the javascript submitForm method but it doesnt inserts anything wat to do
<%@LANGUAGE="VBSCRIPT"%>

<!--#include file="Connections/strConnectString.asp" -->
<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_strConnectString_STRING
  MM_editTable = "Directory_Reg"
  MM_editRedirectUrl = ""
  MM_fieldsStr  = "business_name|value|business_address|value|business_description|value|contact_name|value|mobile|value|telephone|value|email|value|odetails|value|Main|value|CategoryList|value|Listing|value"
  MM_columnsStr = "Business_Name|',none,''|Business_Address|',none,''|Business_Description|',none,''|Contact_Name|',none,''|Mobile|',none,''|Telephone|',none,''|Email|',none,''|[Other Details]|',none,''|Main_Directory|',none,''|Directory_Type|',none,''|Listing_Type|',none,''"

  ' create the MM_fields and MM_columns arrays
  MM_fields = Split(MM_fieldsStr, "|")
  MM_columns = Split(MM_columnsStr, "|")
 
  ' set the form values
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
  Next

  ' append the query string to the redirect URL
  If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
      MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
      MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
  End If

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert")) <> "") Then

  ' create the sql insert statement
  MM_tableValues = ""
  MM_dbValues = ""
  For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
      MM_formVal = MM_emptyVal
    Else
      If (MM_altVal <> "") Then
        MM_formVal = MM_altVal
      ElseIf (MM_delim = "'") Then  ' escape quotes
        MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
      Else
        MM_formVal = MM_delim + MM_formVal + MM_delim
      End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
      MM_tableValues = MM_tableValues & ","
      MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
  Next
  MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

  If (Not MM_abortEdit) Then
    ' execute the insert
    Set MM_editCmd = Server.CreateObject("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_editConnection
    MM_editCmd.CommandText = MM_editQuery
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close

    If (MM_editRedirectUrl <> "") Then
      Response.Redirect(MM_editRedirectUrl)
    End If
  End If

End If
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><!-- InstanceBegin template="/Templates/MainInfo.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title></title>
<%
dim strDataPath, strConnectString, objConnection

dim strMain, strCategoryList, objRS, strSelected, strSQL

strMain = Request.Form("Main")
strCategoryList = Request.Form("CategoryList")



sub makeMain()
Dim ObjRS
Dim ObjRS_numRows

Set ObjRS = Server.CreateObject("ADODB.Recordset")
ObjRS.ActiveConnection = MM_strConnectString_STRING
ObjRS.Source = "SELECT Distinct Dir_Name  FROM Main_Dir  ORDER BY Dir_Name"
ObjRS.CursorType = 0
ObjRS.CursorLocation = 2
ObjRS.LockType = 1
ObjRS.Open()
ObjRS_numRows = 0
Response.Write("<option></option>" & VBCRLF )

    do while not objRS.EOF
        if objRS("Dir_Name") = strMain then
            strSelected = " Selected "
        else
            strSelected = ""
        end if
        Response.Write("<option" & strSelected & ">" &_
                 objRS("Dir_Name") & "</option>" & VBCRLF )
        objRS.MoveNext
    loop
    objRS.Close
    set objRS=Nothing
end sub
sub makeCategoryList
if   strMain <> "" then
Dim ObjRS
Dim ObjRS_numRows

Set ObjRS = Server.CreateObject("ADODB.Recordset")
ObjRS.ActiveConnection = MM_strConnectString_STRING
ObjRS.Source = "SELECT DISTINCT  Directory_Menu FROM Sub_Main_Dir WHERE Dir_Name = '" &_
                 strMain & "'  ORDER BY Directory_Menu"
ObjRS.CursorType = 0
ObjRS.CursorLocation = 2
ObjRS.LockType = 1
ObjRS.Open()
ObjRS_numRows = 0
 if objRS.eof then
            Response.Write("<option>No Categories Found</option>")
        else
            Response.Write("<option>Select Category Now</option>" & VBCRLF )
            do while not objRS.EOF
                if objRS("Directory_Menu") <> "" then
                    strSelected = " Selected "
                else
                    strSelected = ""
                end if
                Response.Write("<option" & strSelected & ">" &_
                         objRS("Directory_Menu") & "</option>" & VBCRLF )
                objRS.MoveNext
            loop
        end if
        objRS.Close
        set objRS=Nothing
else
        Response.Write("<option>Select a Directory First</option>")
    end if
end sub

%>


<script language="JavaScript">
<!--
function submitMain(){
    var objForm = document.forms[0];
    objForm.elements['CategoryList'].selectedIndex=0;
    objForm.submit();
}
function submitForm(){
    var objForm = document.forms[0];
    objForm.action = "index.asp";

    return true;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>

<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<style type="text/css">
<!--
@import url("StyleSheets/Text.css");
-->
</style>
</head>

<body link="#0000FF" topmargin="1">
<table width="1018" height="773" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="109" colspan="3" valign="top"><div align="right">
        <table width="1020" border="0" cellpadding="0" cellspacing="0">
          <tr>
            <td align="left" valign="top"><img src="graphics/New/Template/banner.jpg" width="1020" height="104" border="0" usemap="#Map"></td>
          </tr>
        </table>
      </div></td>
  </tr>
  <tr align="left">
    <td height="15" colspan="3"><table width="1020" height="19" border="0" cellpadding="0" cellspacing="0" background="graphics/New/Template/cellbkgrd.jpg">
        <tr>
          <td height="19">&nbsp;</td>
        </tr>
      </table></td>
  </tr>
  <tr>
    <td width="185" height="585" align="left" valign="top" class="MediumTxt"><div align="left"></div>
      <table width="178" border="0" cellspacing="2">
        <tr>
          <td align="left"><!-- InstanceBeginEditable name="text3" --><!-- InstanceEndEditable --></td>
        </tr>
        <tr>
          <td width="172" align="left"><div align="left"><a href="TheLook.htm"><img src="graphics/images/menulook.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="money.htm"><img src="graphics/images/menumoney.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="lifestyles.htm"><img src="graphics/images/menulife.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="directory.htm"><img src="graphics/images/menudirect.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="essentials.htm"><img src="graphics/images/menuessential.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><img src="graphics/images/menuevent.gif" width="170" height="28"></div></td>
        </tr>
        <tr>
          <td height="23" align="left"><div align="left"><a href="BookReview.htm"><img src="graphics/images/menubooks.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="Forum.htm"><img src="graphics/images/menuconnection.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="contactus.htm"><img src="graphics/images/menucontact.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="members.htm"><img src="graphics/images/menumember.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td align="left"><div align="left"><a href="aboutus.htm"><img src="graphics/images/menuabout.gif" width="170" height="28" border="0"></a></div></td>
        </tr>
        <tr>
          <td height="74" align="center"><a href="index.htm"><img src="graphics/images/menuhome.gif" width="96" height="30" border="0"></a></td>
        </tr>
      </table></td>
    <td width="591" align="left" valign="top"><table width="585" border="0">
        <tr>
          <td width="581" align="left" valign="top"><!-- InstanceBeginEditable name="text1" -->
            <div align="center"><br>
              <br>
              <img src="graphics/New/Subtitles/direcReg.jpg" width="269" height="29">
            </div>
            <!-- InstanceEndEditable --></td>
        </tr>
        <tr>
          <td height="105" valign="top"><!-- InstanceBeginEditable name="text2" --><br>
            <form ACTION="<%=MM_editAction%>"  method="POST" name="form1" onSubmit="return submitForm()">
              <table width="75%" border="0" align="center" cellpadding="0">
                <tr>
                  <td width="33%" class="MediumTxt">Business Name</td>
                  <td width="67%" class="MediumTxt"> <input name="business_name" type="text" id="business_name" size="40"value="<%=Request.Form("business_name")%>"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Business Address</td>
                  <td class="MediumTxt"> <textarea name="business_address" cols="30" rows="6" id="business_address"><%=Request.Form("business_address")%></textarea></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Business Description</td>
                  <td class="MediumTxt"> <textarea name="business_description" cols="30" rows="6" id="business_description"><%=Request.Form("business_description")%></textarea></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Contact Name</td>
                  <td class="MediumTxt"> <input name="contact_name" type="text" id="contact_name" value="<%=Request.Form("contact_name")%>" size="40"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Mobile</td>
                  <td class="MediumTxt"> <input name="mobile" type="text" id="mobile" value="<%=Request.Form("mobile")%>" size="40"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Telephone</td>
                  <td class="MediumTxt"> <input name="telephone" type="text" id="telephone" value="<%=Request.Form("telephone")%>" size="40"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Email</td>
                  <td class="MediumTxt"> <input name="email" type="text" id="email" value="<%=Request.Form("email")%>" size="40"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Other Details</td>
                  <td class="MediumTxt"><input name="odetails" type="text" id="odetails2" value="<%=Request.Form("odetails")%>" size="40"></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Directory Type</td>
                  <td class="MediumTxt"><select name="Main" id="Main" onChange="JavaScript:submitMain();">
                      <%call makeMain%>
                    </select></td>
                </tr>
                <tr>
                  <td class="MediumTxt">Category</td>
                  <td class="MediumTxt"><select name="CategoryList" id="CategoryList">
                      <%call makeCategoryList%>
                    </select></td>
                </tr>
                <tr>
                  <td class="MediumTxt"> Listing Type</td>
                  <td class="MediumTxt"><select name="Listing" id="Listing">
                      <option selected>Select One</option>
                      <option value="Free">Free Listing</option>
                      <option value="Paid">Paid Listing</option>
                    </select> </td>
                </tr>
                <tr align="center">
                  <td colspan="2"> <p>&nbsp; </p>
                    <p>
                      <input name="Submit" type="submit" onClick="MM_validateForm('business_name','','R','contact_name','','R','mobile','','R','telephone','','R','email','','RisEmail','odetails2','','R','business_address','','R','business_description','','R');return document.MM_returnValue" value="Submit Information">
                    </p></td>
                </tr>
              </table>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <p>&nbsp;</p>
              <input type="hidden" name="MM_insert" value="form1">
            </form>
            <br>
            <!-- InstanceEndEditable --></td>
        </tr>
      </table></td>
    <td width="242" align="right" valign="top"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="242" height="585">
        <param name="movie" value="flash/home%20navigation2.swf">
        <param name="quality" value="high">
        <embed src="flash/home%20navigation2.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="242" height="585"></embed></object></td>
  </tr>
  <tr bgcolor="#CC3333">
    <td height="6" colspan="3" align="center" valign="top" class="smalltxt">3</td>
  </tr>
  <tr>
    <td height="53" align="center" valign="top">&nbsp;</td>
    <td align="center" valign="top" class="smalltxt1"><div align="center" class="smalltxt2"><br>
        &copy;2003 mylifestylesolutions.com. A product of Media Business Company
        <br>
        74 Raymond Njoku Street, Ikoyi, Lagos. +234 803 325 4159<br>
        Re-Designed by<font color="#0000FF"> <a href="http://www.bizdatausa.com">BIZDATAUSA
        Inc.</a></font></div></td>
    <td align="right" valign="top">&nbsp;</td>
  </tr>
</table>
<map name="Map">
  <area shape="rect" coords="5,31,134,48" href="login.asp">
  <area shape="rect" coords="6,50,161,67" href="membership.htm">
</map>
</body>
<!-- InstanceEnd --></html>

Start Free Trial
[+][-]10.03.2005 at 07:42AM PDT, ID: 15006802

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.03.2005 at 08:03AM PDT, ID: 15006981

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: javascript, box, populating, insert
Sign Up Now!
Solution Provided By: alambres
Participating Experts: 2
Solution Grade: C
 
 
 
Loading Advertisement...
20080716-EE-VQP-32