473,399 Members | 2,478 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,399 software developers and data experts.

constructing form parameters

In a javascript method, I have a form name.

Given that form name, I want to be able to read all its paramter names and their values. and construct in the form of "name="+encodeURI("value")+"&" and so on so that I can pass the final string to the ".send" method of xmlhttp.

Is there a helper function that does this already? Or which functions should I use to iterate through any given form with just its name.
Apr 14 '08 #1
4 1230
acoder
16,027 Expert Mod 8TB
Use the elements array and loop over it to get all the elements. If you have different types of elements, e.g. text fields, checkboxes, radio buttons, select drop-downs, etc., you will need to deal with them differently to get the values and simulate a GET/POST form submission.
Apr 14 '08 #2
gits
5,390 Expert Mod 4TB
to give one more hint on how you could do that ... just create a function like this:

Expand|Select|Wrap|Line Numbers
  1. /**
  2.  * retrieves the values of nodes within a base-node
  3.  * @param base_node node-ref
  4.  * @return obj object with corresponding key-value-pairs
  5.  */
  6. function get_values(base_node) {
  7.     // just a list with relevant fields - adapt it to your needs
  8.     var tags = { input: 1, select: 1 };
  9.     var obj  = {};
  10.  
  11.     // we loop through the tag list here
  12.     for (var i in tags) {
  13.         var nodes = base_node.getElementsByTagName(i);
  14.  
  15.         // we loop through the node list - actually without checking for 
  16.         // type == 'text' or whatever
  17.         for (var j = 0, n; n = nodes[j]; j++) {
  18.             obj[n.name] = n.value;
  19.         }
  20.     }
  21.  
  22.     return obj;
  23. }
  24.  
so with that you could start to build a next function that builds a query-string for you with the returned obj, or build it into the shown method and return the query-string here instead of the obj ...

good luck ... :)
Apr 16 '08 #3
acoder
16,027 Expert Mod 8TB
Nice! However, it would need to be adapted to allow for radio buttons and checkboxes since you only want checked buttons/boxes, and multiple select elements (where you only want selected options).
Apr 16 '08 #4
gits
5,390 Expert Mod 4TB
Nice! However, it would need to be adapted to allow for radio buttons and checkboxes since you only want checked buttons/boxes, and multiple select elements (where you only want selected options).
that's right :) ... the function would need handling for different input-types and or attributes of elements that could be of interest ... but with such a function you would always have the handling of the ddocument's content in one place ... so antime you need another node handled you just could adapt it here ...

it is a typical framework-function and i assume that everything that calls itself a javascript(ajax)-framework has something like that implemented :) ... or at least it should have ...

kind regards
Apr 16 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Gregory A Greenman | last post by:
I'm trying to write a program in vb.net to automate filling out a series of forms on a website. There are three forms I need to fill out in sequence. The first one is urlencoded. My program is...
7
by: Last Timer | last post by:
class A { public: A(int a, int b) { this.a=a; this.b=b}; int a; int b; } class B : x(3), y(3), public A(1,3) {
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
2
by: Jerry Spence1 | last post by:
One way of passing data to a thread is to encapsulate the thread inside a class. However, I can't refer to my main form objects from within the class/thread as it says "Reference to a non-shared...
7
by: Lee Crabtree | last post by:
I remember when I was first getting into .NET Forms programming that there was a rather emphatic rule about not constructing a form before calling Application.Run with it. So this: ...
10
by: sara | last post by:
Hi - I have been struggling with solution ideas for this now for almost 2 weeks, and have not been able to figure this out. I have a user who creates a Purchase Order (tblPOData). In some...
16
by: xz | last post by:
For example, I have a Class Date with internal variable year, month and day. In Java I would write: class Date{ int year; int month; int day; Date(int year, int month, int day) { this.year...
0
by: nagar | last post by:
I'm using SQLite with the ADO.NET 2.0 SQLite Data Provider as the storage of my application. I chose to use an untyped dataset and I'm using a dataadapter to report changes to the DB. The query...
1
by: Brent White | last post by:
I can't figure out what I'm doing differently with this one drop-down list control from the other two that are working just fine. Background: I am constructing a page that will allow a user to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...

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.