This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Basic question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Basic question" Watch "Basic question" New topic
Author

Basic question

Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
How can is submit the page on a link and set the action on itself?


jherald
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
onclick="document.formName.submit();return false;"

and

don't set an action.

Eric
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
what will i put on the href
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
here's the piece of code that i have:


<%if(currentPage==1 && page3!=0 && page3>numPerPage){%>
[
<a name="next" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=next&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Next</a> |
<a name="last" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=last&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Last</a> ]
<%}else if(currentPage==totalPage && page3!=0 && page3>numPerPage){%>
[
<a name="first" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=first&totPage=<%=totalPage%>&curPage=<%=currentPage%>">First</a> |
<a name="prev" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=prev&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Previous</a>
]
<%}else if(currentPage>1 || currentPage<totalPage && page3!=0 && page3>numPerPage){%>
<a name="first" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=first&totPage=<%=totalPage%>&curPage=<%=currentPage%>">First</a> | 
<a name="prev" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=prev&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Previous</a> | 
<a name="next" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=next&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Next</a> | 
<a name="last" href="approverList.jsp?processId=<%=processId%>&pages1=<%=page1%>&pages2=<%=page2%>&pages=last&totPage=<%=totalPage%>&curPage=<%=currentPage%>">Last</a>
<%}else{%>
 
<%}%>

i want also to submit the page on itslef if ic lcik one of those links
Christian Gross
Author
Ranch Hand

Joined: Feb 20, 2006
Posts: 85
I looked at your code and decided to create a simple little example using Ajax.

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script language="JavaScript" src="/lib/factory.js"></script>
<script language="JavaScript" src="/lib/asynchronous.js"></script>
<script language="JavaScript" type="text/javascript">

var asynchronous = new Asynchronous();

asynchronous.complete = function( status, statusText, responseText, responseXML) {
if( status == 200) {
location.href = responseText;
}
else {
window.alert( "Error (" + statusText + " " ;
}
}

function DoPost( link) {
var buffer = "clickedLink=" + link.href;
asynchronous.post( "/ajaxjavascript/postprocessor", "application/x-www-form-urlencoded", buffer, buffer.length);
return false;
}

</script>


</head>
<body>
<a href="/link/to/send/to/server" onclick="return DoPost( this)">Some link</a>
<a href="/another/link/to/send/to/server" onclick="return DoPost( this)">Another link</a>
</body>
</html>

In the example what happens is that Ajax is used to POST the data to the server, and in the response you navigate the page that the server returns.

The sequence of events are as follows:
1) User clicks on link
2) onclick event of link is activated calling the function DoPost passing the link element as parameter.
3) Function DoPost creates an HTTP POST request using form encoding by creating the form variable clickedLink. The value of clickedLink is the link.href property.
4) Data is sent to the server using an HTTP POST to the servlet URL /ajaxjavascript/postprocessor that is encapsulated by the Asynchronous class defined by the file /lib/asynchronous.js located at the URL http://www.devspace.com:8080/lib/asynchronous.js as well as http://www.devspace.com:8080/lib/factory.js for the XMLHttpRequest factory.
5) The server receives the HTTP POST and extracts clickedLink that contains the href information of the received request.
6) Server processes the data and generates data that consists of a single line representing the URL that the browser will navigate to.
7) Client receives the HTTP POSTED data from the server in the asynchronous.complete method and verifies that the POST was successful. If successful reads the received link and assigns to location.href causing the browser to navigate to the next HTML page.

This process is a little bit more than you want, but it gives you the flexibility on how and what your want to process, ok? Or did I miss the mark?

Christian


Author of Ajax Patterns and Best Practices
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
to answer the how to do it in the href (which is not the best thing to do)

href="javascript ocument.formName.submit();"

Eric
Jherald Lacambra
Ranch Hand

Joined: Feb 02, 2005
Posts: 129
Thanks for the reply.. now I have an idea how to do my application using ajax and/or javascript only
 
Consider Paul's rocket mass heater.
 
subject: Basic question