steve stevo wrote:
There is no short cut - you will have to make a request to the server.
"Smoke" <sm***@xatrium.com> wrote in message
news:zCtpb.137088$sp2.55609@lakeread04... Does anyone know of a quick method of inserting records into a text file
or database using OnClick?
Assuming the database or text file he wants to insert data into is on the
server, he has to make a request to the server. However, he can use a variety
of "shortcuts" which do not involve using POST or GET with a form. Here is a
simple example:
<form name="myForm">
<input type="text" name="theValue" />
<input type="button" value="Insert" onclick="insertValue(this.form);" />
</form>
<script type="text/javascript">
function insertValue(f) {
var cgiCaller = new Image();
cgiCaller.src = 'somethingThatInsertsTheValue.cgi?theValue=' +
f.theValue.value;
}
</script>
Of course there are obvious disadvantages to doing this. Client-side
JavaScript has to be enabled, you can't retrieve any sort of information about
whether the insert was successful or not, etc. I don't recommend doing this
unless you really don't care if the server did what you just asked it to do,
but it is an option if that's your requirement.
The advantages are that you do not need to reload the user's browser, even to
reload the form, so the user can probably send data to the server as fast as
they can change the value in the input and click the button.
The same sort of "shortcut" can be done using the HTTP Request object <url:
http://jibbering.com/2002/4/httprequest.html />. However, because of the added
complexity of implementing it, I usually find it easier to POST a form when I
need to get information back from the server about the state of the
transaction I just asked it to perform. The additional benefit of a POST or
GET is that it will still work even if the user has disabled client-side
JavaScript.
--
| Grant Wagner <gw*****@agricoreunited.com>
* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html
* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp
* Netscape 6/7 DOM Reference available at:
*
http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
*
http://www.mozilla.org/docs/web-deve...upgrade_2.html