Improve company productivity with a Business Account.Sign Up

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

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

0
fstinc
Asked:
fstinc
  • 3
  • 3
  • 3
  • +3
6 Solutions
 
HainKurtSr. System AnalystCommented:
use button

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

0
 
hosneylkCommented:
you could try something like this..
onclick="window.location.href='assetlist.asp';return false;;"

Open in new window

0
 
scrathcyboyCommented:
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
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

 
sammySeltzerCommented:
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
 
ddaanniieellukCommented:
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
 
fstincAuthor Commented:
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
 
HainKurtSr. System AnalystCommented:
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
 
fstincAuthor Commented:
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
 
HainKurtSr. System AnalystCommented:
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
 
fstincAuthor Commented:
I think this is Javascript. I am using Vbscript
0
 
sammySeltzerCommented:
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
 
sammySeltzerCommented:
sorry, didn't know you got it resolved.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

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