Hi,

The form must be on the page that has the button. Here is a simple example
(watch for line breaks in the M_findObj):

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
// cross platform/browser object finder
// you could probably use a simpler one just for your form
function MM_findObj(n, d) { file://v3.0
  var p,i,x;  if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++)
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++)
x=MM_findObj(n,d.layers[i].document); return x;
}

function formSubmit(formaction) {
  // form name could be a parameter too
  formObj = MM_findObj('test');
  formObj.action = formaction;
  alert(formObj.action);
  formObj.submit();
}

file://-->
</script>
</head>

<body bgcolor="#FFFFFF">
<form name="test" method="post" action="">
  <p>
    <input type="text" name="textfield">
    <br>
  </p>
  <p>
    <input type="text" name="textfield2">
  </p>
  <p>
    <input type="button" name="Button1" value="Button"
onClick="formSubmit('servlet/TheFirstServlet');">
    <input type="button" name="Button2" value="Button"
onClick="formSubmit('servlet/TheSecondServlet');">
  </p>
</form>
</body>
</html>






----- Original Message -----
From: "PALLUEL Sylvie" <[EMAIL PROTECTED]>
To: "A mailing list for discussion about Sun Microsystem's Java Servlet API
Technology." <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Tuesday, February 27, 2001 9:03 AM
Subject: Re: Question: Call to Servlet (that doesn't generate HTML) from


> Hello,
> you  answered this last day, but I don't understand very well :
> to do this we need an existing form ? Where must be this form ? In the
current
> HTML page or in any HTML file ?
> My problem is that I'ld like to use two different ways to call my servlet
:
> Searching a keyword in database :
> . using a search form where the user enter the word to search, and click
on
> submit (that's ok)
> . using javascript to click in a input field (part of an other form) which
> content the word to search , and call my servlet with the selected word as
> parameter ...
>
> Bye,
> Sylvie.
>
>
> Robert Koberg a écrit :
>
> > I posted this the other day. I don't know why people use "location".
This is
> > how it should be done:
> >
> > <a
href="javascript:myFormFunction('/servlet/ServletName','formName')>text
> > or image</a>
> >
> > Then in the head of the document (or js include) put a function
something
> > like:
> >
> > <script>
> > function myFormFunction(theAction, theForm) {
> >     // custom cross platform function that gets an object..
> >     // create your own or take Dreamweaver's - MM_findObj or something
like
> > that
> >     myFormObj = getObject(theForm) ;
> >     // set the action
> >     myFormObj.action = theAction;
> >     myForm.submit();
> > }
> > </script>
> >
>

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to