Link to home
Start Free TrialLog in
Avatar of fstinc
fstinc

asked on

Onclick redirect

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")%>">

ASKER CERTIFIED SOLUTION
Avatar of HainKurt
HainKurt
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you could try something like this..
onclick="window.location.href='assetlist.asp';return false;;"

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fstinc
fstinc

ASKER

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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fstinc

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of fstinc

ASKER

I think this is Javascript. I am using Vbscript
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&""%>



sorry, didn't know you got it resolved.