• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Basic question

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can is submit the page on a link and set the action on itself?
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
onclick="document.formName.submit();return false;"

and

don't set an action.

Eric
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what will i put on the href
 
Jherald Lacambra
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 85
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.. now I have an idea how to do my application using ajax and/or javascript only
 
reply
    Bookmark Topic Watch Topic
  • New Topic