Solved

Onclick redirect

Posted on 2010-11-11
12
2,931 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +3
12 Comments
 
LVL 53

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 29

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 53

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 53

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 29

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 29

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

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
Find out what you should include to make the best professional email signature for your organization.
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

751 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