Author |
Topic |
|
lsakizada
New Member
USA
90 Posts |
Posted - 04 September 2003 : 04:30:05
|
Hi, I am having a problem to create a link that can behave as a form's submit button. This link should pass variables between pages.
I created this JavaScript function: ----------------------------------------------------------------- Response.Write "<script language=""JavaScript"" type=""text/JavaScript"" >" & vbNewLine & _ "function GetSupport3Vars(selectedtype1, selectedtype2, selectedtype3){" & vbNewLine & _ "document.supportform.ContentID.value = selectedtype1 ;" & vbNewLine & _ "document.supportform.CategoryID.value = selectedtype2 ;" & vbNewLine & _ "document.supportform.State.value = selectedtype3 ;" & vbNewLine & _ "document.supportform.submit();}" & vbNewLine & _ "</script>" ------------------------------------------------------------------
and I am calling the function using this syntax (See in red)
------------------------------------------------------------------
sub DisplayCategories(byval IsLeft, byval Width, byval sStates, byval State)
dim rsCatList, rsContList dim lItemsToDisplay, lCategoryID if IsLeft then lItemsToDisplay = strCMSLeftNavItems else lItemsToDisplay = strCMSRightNavItems if sStates = "" then sStates = State end if 'Get categories which have approved content strSql = "SELECT DISTINCT " strSql = strSql & strTablePrefix & "CMS_CATEGORY.CAT_ID, " strSql = strSql & strTablePrefix & "CMS_CATEGORY.CAT_TITLE, " strSql = strSql & strTablePrefix & "CMS_CATEGORY.CAT_ORDER, " strSql = strSql & strTablePrefix & "CMS_CATEGORY.STATE, " ' strSql = strSql & strTablePrefix & "CMS_CONTENT.CONT_STATE_STATUS " strSql = strSql & "FROM " & strTablePrefix & "CMS_CATEGORY, " & strTablePrefix & "CMS_CONTENT " strSql = strSql & "WHERE " & strTablePrefix & "CMS_CATEGORY.CAT_ISLEFT = " & IsLeft & " " strSql = strSql & "AND " & strTablePrefix & "CMS_CONTENT.CONT_STATUS = 1 " strSql = strSql & "AND " & strTablePrefix & "CMS_CATEGORY.CAT_ID = " & strTablePrefix & "CMS_CONTENT.CAT_ID " if sStates <> "" then strSql = strSql & "AND " & strTablePrefix & "CMS_CONTENT.CONT_STATE_STATUS = " & "'" & "" & sStates & "" & "'" & " " end if strSql = strSql & "ORDER BY " & strTablePrefix & "CMS_CATEGORY.CAT_ORDER ASC" set rsCatList = my_Conn.Execute(strSql) do while NOT rsCatList.EOF lCategoryID = rsCatList.Fields("CAT_ID").Value call StartTable(Width, rsCatList.Fields("CAT_TITLE").Value) strSql = "SELECT " strSql = strSql & strTablePrefix & "CMS_CONTENT.CONT_ID, " strSql = strSql & strTablePrefix & "CMS_CONTENT.CONT_TITLE " strSql = strSql & "FROM " & strTablePrefix & "CMS_CONTENT " strSql = strSql & "WHERE " & strTablePrefix & "CMS_CONTENT.CAT_ID = " & lCategoryID & " "
strSql = strSql & "ORDER BY " & strTablePrefix & "CMS_CONTENT.CONT_LAST_EDIT ASC" set rsContList = Server.CreateObject("ADODB.Recordset") rsContList.CursorLocation = adUseClient rsContList.Open strSql, my_Conn
do while NOT rsContList.EOF and rsContList.AbsolutePosition <= CInt(lItemsToDisplay)
' Response.Write "<a href="""& Request.ServerVariables("SCRIPTNAME") &"?ContentID="& rsContList.Fields("CONT_ID").Value &"&CategoryID="& lCategoryID &""">"& rsContList.Fields("CONT_TITLE").value &"</a><br />" ' Response.Write "<a href="""& Request.ServerVariables("SCRIPTNAME") &"?ContentID="& rsContList.Fields("CONT_ID").Value &"&CategoryID="& lCategoryID &"&State="& sStates &""">"& 'rsContList.Fields("CONT_TITLE").value &"</a><br />" Response.Write "<Form name=""supportform"" method=""post"" action=""Portal.asp"" >" & vbNewLine & _ "<input type=""hidden"" name =""ContentID"" />" & vbNewLine & _ "<input type=""hidden"" name =""CategoryID"" />" & vbNewLine & _ "<input type=""hidden"" name =""State"" />" & vbNewLine & _ "<a href=""javascript:GetSupport3Vars(" & "'" & CInt(rsContList.Fields("CONT_ID").Value) & "'" & "," & "'" & lCategoryID & "'" & "," & "'" & sStates & "'" &")"" >" &rsContList.Fields("CONT_TITLE").value & "</a><br />" & _
"</form>"
rsContList.MoveNext loop if rsContList.RecordCount > CInt(lItemsToDisplay) then Response.Write "<a href="""& sThisPage &"?CategoryID="& lCategoryID &""">more "& rsCatList.Fields("CAT_TITLE").value &"....</a>" end if set rsContList = nothing call EndTable() rsCatList.MoveNext loop set rsCatList = nothing
end sub
------------------------------------------------------------
The Error iscomming up on clicking on the link
"Error: document.supportform.selectedtype1' is null or not an object"
Please help me I lost all my hair
|
Edited by - lsakizada on 05 September 2003 02:33:12 |
|
Gremlin
General Help Moderator
New Zealand
7528 Posts |
Posted - 04 September 2003 : 05:32:23
|
Why not just use "javascript:this.form.submit();" |
Kiwihosting.Net - The Forum Hosting Specialists
|
|
|
lsakizada
New Member
USA
90 Posts |
Posted - 04 September 2003 : 13:01:05
|
The links that created during the procedure with <a href ""..> should behave as a submit button, So I guess this wont work. I think so since the forms variables should pass when cklicking on link that capure on browser. |
|
|
lsakizada
New Member
USA
90 Posts |
Posted - 05 September 2003 : 02:38:16
|
Hi,
I have not got much response So I'll give one more try.
i created this button on a test file and its working fine, but on the real file it is not. Can you see whats the problem?
--------------------> This is the test file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE>
<%
Response.Write "<script language=""JavaScript"" type=""text/JavaScript"" >" & vbNewLine & _ "function GetSupport2Vars(selectedtype1, selectedtype2, selectedtype3){" & vbNewLine & _ "document.supportform.selectedtype1.value = selectedtype1 ;" & vbNewLine & _ "document.supportform.selectedtype2.value = selectedtype2 ;" & vbNewLine & _ "document.supportform.selectedtype3.value = selectedtype3 ;" & vbNewLine & _ "document.supportform.submit();}" & vbNewLine & _ "</script>" & vbNewLine & _ %> </HEAD>
<BODY> <% Call AAA() Sub AAA()
Response.Write var1 & " " & var2 var1 = Request.Form("selectedtype1") var2 = Request.Form("selectedtype2") var3 = Request.Form("selectedtype3")
Response.Write var2 & " " & var1 & " " & var3
Response.Write "<Form name=""supportform"" method=""post"" action=""MyTest.asp"" >" & vbNewLine & _ "<input type=""hidden"" name =""selectedtype1"" />" & vbNewLine & _ "<input type=""hidden"" name =""selectedtype2"" />" & vbNewLine & _ "<input type=""hidden"" name =""selectedtype3"" />" & vbNewLine & _ "<a href=""javascript:GetSupport2Vars(" & "'" & "DAN" & "'" &", " & "'" & "SUZY" & "'" & ", " & "'" & "Jeff" & "'" &")"">Support 1</a>" & vbNewLine & _ "<a href=""javascript:GetSupport2Vars(" & "'" & "SUZY" & "'" &", " & "'" & "DAN" & "'" & ", " & "'" & "Jeff" & "'" &")"">Support 2</a>" & vbNewLine & _ "<a href=""javascript:GetSupport2Vars(" & "'" & "SUZY" & "'" &", " & "'" & "Jeff" & "'" & ", " & "'" & "Dan" & "'" &")"">Support 3</a>" & vbNewLine & _
"</form>" end sub %>
</BODY> </HTML> |
|
|
lsakizada
New Member
USA
90 Posts |
Posted - 06 September 2003 : 02:30:09
|
Hi guys, I fixed that!, The problem was that I created on the fly many <Form> during the 'do while' statement, so the code in the JavaScript function does not know which form call it.
So, I had to crete on the fly the forms with different names:
------------------------------------------------------------------- Response.Write "<Form name=""supportform" & Counter & """ & method=""post"" action=""Portal.asp"" >" & vbNewLine & _ "<input type=""hidden"" name =""ContentID"" />" & vbNewLine & _ "<input type=""hidden"" name =""CategoryID"" />" & vbNewLine & _ "<input type=""hidden"" name =""State"" />" & vbNewLine & _ "<a href=""javascript:GetSupport3Vars(" & "'" & CInt(rsContList.Fields("CONT_ID").Value) & "'" & "," & "'" & lCategoryID & "'" & "," & "'" & sStates & "'" &")"" >" &rsContList.Fields("CONT_TITLE").value & "</a><br />" & _ "</form>"
counter = counter + 1 -----------------------------------------------------------
Where counter initialized to 0 before each loop.
and the JavaScript function looks like that:
----------------------------------------------- Response.Write "<script language=""JavaScript"" type=""text/JavaScript"" >" & vbNewLine & _ "function GetSupport3Vars(ContentID, CategoryID, State){" & vbNewLine & _ "this.supportform.ContentID.value = ContentID ;" & vbNewLine & _ "this.supportform.CategoryID.value = CategoryID ;" & vbNewLine & _ "this.supportform.State.value = State ;" & vbNewLine & _ "this.supportform.submit();}" & vbNewLine & _ "</script>" -----------------------------------------------------------------
You better learn this code since it help send form parameters via links and not from submit button. beside of that its can be used during subrootins.
I will be glad to answer question.
|
Edited by - lsakizada on 06 September 2003 02:32:43 |
|
|
|
Topic |
|
|
|