Solved

Onclick redirect

Posted on 2010-11-11
12
2,881 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:
HainKurt 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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:HainKurt
HainKurt 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:HainKurt
HainKurt 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

825 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