Solved

Onclick redirect

Posted on 2010-11-11
12
2,901 Views
Last Modified: 2012-05-10
I have a html form set up. It has a detete, update and assets button next to each username on the form. I need the page to redirect to assetlist.asp page when the asset button is clicked. Heres what I got. When it redirects, it should list all assets associated with that specific user.

                                    <INPUT type = "Submit" name = "Assets" value = "Redirect"
                                    onclick="window.location.href='assetlist.asp';">

Problem is, since its a form it always refreshes to the exact same page. If I change the page, then the update button will not work. Any suggestions?

<FORM method = "post" action = "assetlist.asp?userid=<%=objRS("USERID")%>">

0
Comment
Question by:fstinc
  • 3
  • 3
  • 3
  • +3
12 Comments
 
LVL 51

Accepted Solution

by:
Huseyin KAHRAMAN earned 251 total points
ID: 34117208
use button

<button onclick="window.location.href='assetlist.asp?userid=<%=objRS("USERID")%>'">Redirect</button>

0
 
LVL 10

Expert Comment

by:hosneylk
ID: 34117215
you could try something like this..
onclick="window.location.href='assetlist.asp';return false;;"

Open in new window

0
 
LVL 44

Assisted Solution

by:scrathcyboy
scrathcyboy earned 83 total points
ID: 34117252
The link HAS to go to the ASP page with parameters, like this --

onclick="window.location.href='assetlist.asp?userid=jane%20fonda+getvars=whatUwant';">

the userid and the getvars needs to be parameters submitted by the form that the ASP page is to process

0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 28

Assisted Solution

by:sammySeltzer
sammySeltzer earned 83 total points
ID: 34117441
This is *how* i have always done it and it has never failed me.

<INPUT type = "Submit" name="Assets" VALUE=" Redirect " onClick="location='assetlist.asp?userid=<%=objRS("USERID")%> '"

Open in new window

0
 

Assisted Solution

by:ddaanniieelluk
ddaanniieelluk earned 83 total points
ID: 34119215
Should be a simple bit of code as follows:
<INPUT type = "submit" name="assets" VALUE=" Redirect " onClick="location='assetlist.asp?userid=<%=objRS("USERID")%> '"

Open in new window

0
 

Author Comment

by:fstinc
ID: 34122281
No, The page continues to process each userid and refresh back to the same page. You see, my problem is that this form has action = temporary_user as follows.

<FORM method = "post" action = "temporary_user.asp?userid=<%=objRS("USERID")%>">

But when I change it to this is works fine:

<FORM method = "post" action = "assetlist.asp?userid=<%=objRS("USERID")%>">

However, Then the update button does not work because the update button needs to redisplay all of the users. That is problem.
0
 
LVL 51

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 251 total points
ID: 34123489
do you have a link? or post some screenshots.. looks like nobody understood what is happening on the page...

you say you have a list of two

HainKurt [Delete] [Update] [Asset]
KurtHain [Delete] [Update] [Asset]

when you click [Asset] button it goes to a different page... then what happens? I could not get what you mean by "If I change the page, then the update button will not work"
0
 

Author Comment

by:fstinc
ID: 34124720
The code is attached. Basically, this .asp code is located under temporary_user.asp. the page looks this set up: Theres an IF statement at the top. The IF statement checks if the user presses delete or update. If user presses delete or update then it updates or deletes and goes back to the original page. But if the user presses "Redirect" it does not redirect to the assetlist.asp page. It just goes back to the temporary_user page. The reason is because the form tells the ASP to do so: Hence:
<FORM method = "post" action = "temporary_user.asp?userid=<%=objRS("USERID")%>">

Now,
I know the solution would be to change the form code above to action=assetlist.asp. However, not, the delete and update button do not work. Here is my problem. I want all three to work. Not just 2 buttons. Any suggestions?

<%@ Language=VBScript %>

<%

Option Explicit
Response.Expires = 0

Const section = "user"	

DIM objConn, objRS, strConnection, strQ
DIM assetID, X, userID, objRS2

Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open strConnection

Set objRS = Server.CreateObject("ADODB.Recordset")
Set objRS.ActiveConnection = objConn

Set objRS2 = Server.CreateObject("ADODB.Recordset")
Set objRS2.ActiveConnection = objConn

userID = trim(Request.QueryString("userID"))
'response.Write strq

IF trim(Request.QueryString("userID")) <> "" and Trim(Request.Form("submit")) = "update" Then
		strQ =	"UPDATE USERINFO SET " & _
					" FIRSTNAME = " & SqlQuoteString(Request.Form("firstname")) & ", " & _
					" LASTNAME = " & SqlQuoteString(Request.Form("lastname")) & ", " & _
					" DEPARTMENTNUM = '" & Request.Form("department") & "', " & _
					" ACTIVE = '" & Request.Form("active") & "', " & _
					" ISPERSON = '" & Request.Form("isperson") & "'" & _
				"WHERE USERID = '" & userid & "'"
objConn.Execute (strQ)
End If
		
	
If Trim(Request.Form("delete")) = "Delete!"  Then
		strQ =   "SELECT COUNT(*) as total FROM Assets as b" & _
                        " where b.userid = '" & userid & "'"
				objRS.open( strQ )
				Dim t
				t=objRS.Fields("total")
				objRs.close
				


		if t=0 Then 
				

				strQ =  	 "DELETE a FROM userinfo as a LEFT JOIN Assets as b" & _
                        " on a.userID = b.userID" & _
                        " where b.assetid is  null" & _
                        " and a.userid = '" & userid & "'"
				
				
				ObjConn.Execute (strQ)
		End If
		If t<>0 THEN
				

				strQ =  "SELECT b.assetID, b.assetDescription FROM userinfo as a LEFT JOIN Assets as b" & _
                        " on a.userID = b.userID" & _
                        " where a.userid = '" & userid & "'"
						

				objRS.open( strQ )

		While not objRS.EOF
			Response.Write objRS("assetID") & "   Asset Description:" & objRS("assetDescription") & "<br>"
			  objRS.Movenext
		Wend

		objRs.close


		End If
	 End If 'Form field check	 
	 
	 If Trim(Request.Form("userassets")) = "redirect"  Then
		userid = request.Form("userassets")
		Response.Redirect("assetlist.asp?userid=" & userid & "")
	End If
	

strQ =	"SELECT USERID,LASTNAME,FIRSTNAME,ACTIVE,ISPERSON, DEPARTMENTNUM " & _
		"FROM USERINFO " & _
		"ORDER BY ACTIVE DESC, LASTNAME"

'Response.Write strQ

objRS.Open(strQ)

strQ =	"SELECT DEPARTMENTID, DEPARTMENT FROM DEPARTMENT (NOLOCK)" 
objRS2.Open strQ
'response.Write strq
'response.end
%>


<!-- #INCLUDE FILE = "nav.asp" -->

<HTML>
<body>
      </div>
      <div align="left"></div>
      <div align="left"><br></div>
      <div align="left"></div>
      <A href = "addauser.asp">Add new user</A>


     <% 
      IF Request.QueryString("newuser") = "yup" THEN
			Response.Write "<CENTER><P><FONT COLOR = RED>New user Added</FONT></P></CENTER>"
	  END IF
	  %>
      
      
      <table width="800" border="1" cellspacing="0" cellpadding="0" bordercolor=#BBBBBB align="center">
        <tr> 
          <td bgcolor=<%=maincolor%> bordercolor="<%=maincolor%>"> 
            <p align="center"><b><font color="#FFFFFF">User List/Edit</font></b></p>
          </td>
        </tr>
        <tr> 
          <td height="89"> 
            <div align="center"> 
              <table width="100%" border="0" cellspacing="3" cellpadding="0">
                <tr> 
                      <td width="10%"> 
                    <p>First</p>
                  </td>
                  <td width="10%"> 
                    <p>Last</p>
                   </td>
                  <td width="16%">
					<p>Department</p>
                  </td>
                  <td width="10%"> 
                    <p>Active</p>
                  </td>
                  <td width="10%"> 
                    <p>Person</p>
                  </td>
                  <td width="51%"> 
                    <p>Save Changes</p>
                  </td>
                </tr>
                <%X = 1
              
              While not objRS.EOF %>
                <FORM method = "post" action = "temporary_user.asp?userid=<%=objRS("USERID")%>">
                  <tr> 
                    <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>> 
                      <p> 
                        <Input type = text value = "<%=objRS("FIRSTNAME")%>" name=firstname>
                      </p>
                    </td>
                    <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>> 
                      <p> 
                        <Input type = text value = "<%=objRS("LASTNAME")%>" name=lastname>
                      </p>
                    </td>
                                  <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>>
                          
                          <select name = "department" ID="Select2">
                            
                            <%objRS2.movefirst%>
							<%While not objRS2.EOF %>
                            
                            
								<option value = <%=objRS2("DEPARTMENTID")%> 
							<%
								If objRS2("DEPARTMENTID") = objRS("DEPARTMENTNUM") Then
									Response.Write (" selected")
								End If  

                            %>
                            <font size="-1"> 
                            <%  Response.Write objRS2("department")%>
                            </font></option>
                            <%objRS2.Movenext
								Wend%>
                          </select>      
                    </td>
                    <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>> 
                      <p> 
                        <SELECT name = active>
                          <OPTION value = "1" <%IF objRS("ACTIVE") = "True" THEN
									Response.Write " Selected"
								  END IF%>>Yes</OPTION>
                          <OPTION value = "0" <%IF objRS("ACTIVE") = "False" THEN
									Response.Write " Selected"
								  END IF%>>No</OPTION>
                        </SELECT>
                        <%IF objRS("ACTIVE") = "False" THEN
								Response.Write "<FONT color = red>*</FONT>"
						  END IF %>
                      </p>
                    </td>
                    <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>> 
                      <p> 
                        <SELECT name=isperson>
                          <OPTION value = "1" <%IF objRS("ISPERSON") = "True" THEN
									Response.Write " Selected"
								  END IF%>>Yes</OPTION>
                          <OPTION value = "0" <%IF objRS("ISPERSON") = "False" THEN
									Response.Write " Selected"
								  END IF%>>No</OPTION>
                        </SELECT>
                        <%IF objRS("ISPERSON") = "False" THEN
								Response.Write " <FONT color = red>*</FONT> "
						  END IF %>                      
                      </p>
                    </td>
                    <td 
                  <%IF x mod 2 = 0 THEN
						Response.Write " bgcolor = #EEEEEE"
					END IF%>> 
                      <p>
                        <INPUT type = "Submit" name = "submit" value = "Update">
						<INPUT type = "submit" name = "Delete" value = "Delete!" 
		                onclick="return confirm('Are you sure you want to delete?');">
						<INPUT type = "Submit" name = "Assets" value = "Redirect" 
						onclick="window.location.href='assetlist.asp?userid=jane%20fonda+getvars=whatUwant';">						
						<button onclick="window.location.href='assetlist.asp?userid=<%=objRS("USERID")%>'">Redirect</button>
						<INPUT type = "Submit" name="Assets" VALUE=" Redirect " onClick="location='assetlist.asp?userid=<%=objRS("USERID")%> '"
   <INPUT type = "submit" name="assets" VALUE=" Redirect " onClick="location='assetlist.asp?
					  </p>

                    </td>
                  </tr>
                </FORM>
				   
                
                <% X=X+1
             objRS.MoveNext
			   Wend%>
                <tr> 
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  <td> 
                    <p>&nbsp;</p>
                  </td>
                  
                    <td> 
                    <p>&nbsp;</p>
                  </td>
                </tr>
              </table>
            </div>
          </td>
        </tr>
      </table>
      <p align="center"> </p>
    </td>
  </tr>

</table>
</body>
</html>

<%
'clean up 
objRS.Close
objRS2.close
objConn.Close

Set objConn = nothing
Set objRS = nothing
Set objRS2 = nothing

FUNCTION SQLQuoteString(ByVal strValue)
	Dim intPos

	If IsNull(strValue) Then
		SQLQuoteString = "NULL"
	Else
		For intPos = Len(strValue) To 1 Step -1
			If Mid(strValue, intPos, 1) = "'" Then
				' Insert extra "'"
				strValue = Left(strValue, intPos - 1) & "'" & Mid(strValue, intPos)
			End If
		Next
		SQLQuoteString = NullEmpty("'" & strValue & "'")
	End If
END FUNCTION

FUNCTION NullEmpty(varValue)
	If IsNull(varValue) Then
		NullEmpty = "NULL"
	ElseIf (varValue = "''") Or (varValue = "") Then
		NullEmpty = "NULL"
	Else
		NullEmpty = varValue
	End If
END FUNCTION
%>

Open in new window

ScreenShot005.jpg
ScreenShot004.jpg
0
 
LVL 51

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 251 total points
ID: 34124805
maybe this (on client side):

onClick="gotoAsset('<%=objRS("USERID")%>')"

function gotoAsset(userid){
  document.forms[0].action="assetlist.asp?userid=" + userid;
  //document.forms[0].submit();
}
0
 

Author Comment

by:fstinc
ID: 34138174
I think this is Javascript. I am using Vbscript
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34139370
I *think* that the issue you are having is that you are processing everything on *ONE* page - which is fine.

If that is the case, then you should *NOT* use:

<action=temporary_user.asp>

Remove that part of your code and then under the form, pass the IDs as hidden form

then at the top where you are processing your input, you can then do something like::


IF trim(Request.QueryString("userID")) <> "" and Trim(Request.Form("submit")) = "update" Then
            strQ =      "UPDATE USERINFO SET " & _
                              " FIRSTNAME = " & SqlQuoteString(Request.Form("firstname")) & ", " & _
                              " LASTNAME = " & SqlQuoteString(Request.Form("lastname")) & ", " & _
                              " DEPARTMENTNUM = '" & Request.Form("department") & "', " & _
                              " ACTIVE = '" & Request.Form("active") & "', " & _
                              " ISPERSON = '" & Request.Form("isperson") & "'" & _
                        "WHERE USERID = '" & userid & "'"
objConn.Execute (strQ)
<head>
      <title>Create Another Record</title>
      <META HTTP-EQUIV="refresh" content="2;url=whateverpage.asp">
</head>
End If

And if you wish to return a page with a specific id, then something like this:

response.Redirect whateverpage.asp?id="&&somevalue&""%>



0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 34139389
sorry, didn't know you got it resolved.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Date on a table 16 33
SSMS Imprt data from Excel 7 19
Hide and Unhide Table 6 24
StoredProcedure to JSON query faulty syntax 2 22
This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

679 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