473,232 Members | 1,425 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,232 software developers and data experts.

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 32993
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.
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.