• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

post to servlet JavaScript style

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i am struggling with how to issue a submit,method=post type
command WITHOUT a button. I can't seem to get an onload
type invocation.
If i place a button on the form and press it, the servlet is
called correctly.
If i try an onLoad call it does not work.
What would someone do....would you create a hidden button
and then issue a onClick...how is a network command
issued WITHOUT the use of buttons?
sample code:
<script language="javascript">
function postinterfaces(form)
{
// this works when pressing button. form.submit()
alert("help")
form.action="http://machine/servlets/servlet"
form.method="post"
form.elements[0].name="command"
form.elements[0].value="thevalue"
form.submit()
}
function pressButton(form) {
postinterfaces(form)
}
</script>
</HEAD>
<form >
<p><input type="SUBMIT" name="SupList" value="SMUCK" onClick="postinterfaces(this.form)"></p>
</form>
//onload won't work
<body bgcolor="#FFFFBB" onload="pressButton(this.form)">
</body>
</html>

thank you al
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try just having your onLoad function execute the following command:
document.formname.submit();
The formname will be replaced by the name of a form you create with only hidden fields.
Ciao,
------------------
I'm a soldier in the NetScape Wars...
Joel
 
al butler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

still need help.
this is under IE 5.5....right now don't care about NS4+.
Anyone got code on how to issues a POST method, with params
using JScript.
thansks la
 
al butler
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

i got it.
it's bizarre stuff that's for sure.
in a nutshell....when you fire the submit button it
took a different shape as to what "form" i was using
and trying to change the values for the post to work.
When using the onLoad="", it was not working even though
i referenced the this.form as i did for the submit.
So what i had to do....
create a dummy form
<form </form>
remove the button since i don't need it.
add this for the onload
<body ONLOAD="postinterfaces(document.forms[0])"></body>
and my jscript function looks like this:
function postinterfaces(form)
{
form.action="http://host/servlets/servlet?command=list"
form.method="post"
form.submit()
}
note a few things.
i had to combine the "?command=list" text for the onLoad.
However for the submit button i could use :
form.elements[0].....
for onLoad it was null.
may have not got the correct syntax either.
but I'm there!
al

 
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic