473,474 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Post data to server from javascript on client side

Hello everyone,

I have a few values and variables that I want to post to a server
(without using a SUBMIT button). Is there a way to post data from
within javascript - do sockets or connections have to be open for this
to work?

Any help, hints or advice is appreciated :-)

Kindest Regards.

Jul 23 '05 #1
4 33023
milkyway wrote:
Hello everyone,

I have a few values and variables that I want to post to a server
(without using a SUBMIT button). Is there a way to post data from
within javascript - do sockets or connections have to be open for this
to work?

Any help, hints or advice is appreciated :-)

Kindest Regards.


Hi,

Yes, just call the submit() method of a form, like this:

<form action="secretposting.php" name="aForm">
<input type="hidden" name="var1" value="hai">
</form>

<script type="text/javascript">
document.forms["aForm"].submit();
</script>

do sockets or connections have to be open for this to work?
Don't worry about sockets, this is all just plain http/javascript.
But a TCPIP connection that is working comes in very handy when posting
forms. :P
Regards,
Erwin Moller
Jul 23 '05 #2
Hello again everyone :-)

Adding more clarification below ...

Erwin Moller wrote:
milkyway wrote:

Hi,

Yes, just call the submit() method of a form, like this:

<form action="secretposting.php" name="aForm"> <input type="hidden" name="var1" value="hai">

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

the thing is that I do not have an <input ....> defined for every value
I wish to send to the server. I remember (in the old days), the string
sent to the server would sook something like:

http://groupsbeta.google.com/group/c...reply_to=group

See how the '&'is used to separate the <value name / value>
combinations? Something like:

http://clothes.com/run_this?socks=blue&shirts=10& ...

How would one generate the string to send to the server? Is there a
better way to get data to the server?
I am open for any suggestions.

Kindest Regards.

Jul 23 '05 #3
Hello all again,

I found some code that kind of looks similar to what I am trying to
achieve - except here, there is the allowing of the posting of *one*
variable. Is there a way to post many variables (
the idea is that the post will go to server side processing and send
back an HTML page).

Regards,
Milkyway

<FORM ACTION="URLHere" ID="frmone" NAME="frmUser" METHOD="POST" >
....form stuff here
</form>

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

var frmUser = document.getElementById("frmone")
frmUser.submit(frmUser);

-->
</script>

or you could try:

<SCRIPT LANGUAGE="JAVASCRIPT">
<!--

var frmUser = document.frmUser
frmUser.submit(frmUser);

-->
</script>

Jul 23 '05 #4
"milkyway" <d0******@hotmail.com> wrote in message
news:11**********************@c13g2000cwb.googlegr oups.com...
Hello again everyone :-)

Adding more clarification below ...

Erwin Moller wrote:
milkyway wrote:

Hi,

Yes, just call the submit() method of a form, like this:

<form action="secretposting.php" name="aForm">
<input type="hidden" name="var1" value="hai">

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

the thing is that I do not have an <input ....> defined for every
value
I wish to send to the server. I remember (in the old days), the string
sent to the server would sook something like:


So create an <input> for every value you want to send to the server.
http://groupsbeta.google.com/group/c...reply_to=group

See how the '&'is used to separate the <value name / value>
combinations? Something like:
You'll get the exact same thing from:

<form method="GET" action="your_form_handler.jsp">
<!-- note method="GET" -->
<input type="hidden" name="a" value="b">
<input type="hidden" name="c" value="d">
<input type="hidden" name="e" value="f">
http://clothes.com/run_this?socks=blue&shirts=10& ...

How would one generate the string to send to the server? Is there a
better way to get data to the server?
I am open for any suggestions.


Please explain what you are trying to do. If you have a link that
displays a specific product for example, you do something like this _on_
_the_ _server_:

// read the database for product ids and names
// pretend the data returned is in -dataset-
for (var i = 0; i < dataset.rows_returned; ++i) {
print_to_client(
"<a href=\"/products/look_at_product.jsp?" +
"product_id=" +
dataset.getRow(i).getColumn("product_id") +
"\">" +
dataset.getRow(i).getColumn("product_name") +
"</a>"
);
}

Then /products/look_at_product.jsp would do something like:

var product_id = Request.value("product_id");
// run the following SQL safely:
// "select * from products
// where product_id=" + product_id
// (Note: never never never just stick
// untrusted data like -product_id-
// obtained from the client and simply
// use it to build SQL)

// now display the stuff retrieved from
// the database query, or display an
// error if the product couldn't be
// found or whatever

So like I said, please explain what you are attempting to do. I think
you don't need JavaScript at all (but without more details I can't tell
for sure). If you are trying to display information about data you have
on the server, write the links as shown, from the server.

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marcel Brekelmans | last post by:
Hi, This is my situation: My ISP doesn't allow me the execute server-code. So, no ASP or otherwise.As a small compensation, they run some CGI scripts that we can use. With one of these...
0
by: Darrell G | last post by:
I am in need of some good advice ... Goal: I need to automatically log users of my website into a second website. Obstacles: The second website requires I "post" a form with specific...
3
by: David Shorthouse | last post by:
Hey folks, Not an off-topic posting.....since I was shot-down in an earlier post...this one's legit. How do I go about calling a server-side vbscript within a client-side javascript function?...
0
by: Shaul Feldman | last post by:
Hello, I'm trying to find a way to add data (not working with DB) from client-side to server side. Let's say I have a form (page) that a user may add rows (in table) with data. the data is NOT...
9
by: Good Man | last post by:
Hi This is sort of a weird question, perhaps a bit off-topic... I am on the 'edit' screen of a web form, and I have a bunch of variables coming from a database that need to be placed into the...
3
by: =?Utf-8?B?UGV0ZXIgSiwgU2Nhbmlh?= | last post by:
Hello I'm looking for an solution about how to retrive data from an client side located Excel document by using an ASP.Net application. I don't want to upload the file to the server. I just want...
1
by: Anne Marie | last post by:
I am updating a hidden fields' value client side in javascript. The assigned value seems to be correct from the alert message but when I postback the page to server side the value assigned to the...
7
by: Ale | last post by:
can anyone plzzz tell how to store data at the client side using jsp's or servlets?
1
idsanjeev
by: idsanjeev | last post by:
Hello What is server and client side code. where can use server side code and where client side Thanks
3
by: malathib | last post by:
Hi, In my web application, in one of the screen when the user clicks on one link, it has to open a folder that was located in server in client side.
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.