Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically creating a new, invisible form

Status
Not open for further replies.

solmyr72

Programmer
Aug 8, 2004
20
IL
Hi,

I'm writing a javascript for IE 6 (yes, I know it's better to be protable, but we only need it for a limited number of IE 6 users).

I would greately appreciate advice as to whether there's a way to dynamically create a new form which is *invisible* (in memory only), populate it, and then submit the new form.

Notes:
1) I have to use POST, this is why I can only rely on form.submit() . If it were GET, I could manually concatenate required parameters to the server URL, and put it into the navigator. But this won't work for POST.

2) The form needs to be created dynamically, and be invisible. The idea is, I collect data from various crazy controls, do some javascript calculations, and then submit a shorter and clearer parameters list to the server.

In * non-formal * notation, it would be something like:
Code:
// This is not real javascript, just the general way i'd 
// like it to appear!
    // Invisible form in memory:
    form  f=new form();  
    f.method='post';
    // Add parameter "salary=99" :
    f.salary = new textInput();  f.salary.value=99;
    // Add parameter "department=HR":
    f.department=new textInput(); f.department.value='HR';
    // Submit:
    f.submit();

Can this be done in IE 6 , using javascript (not, say, VB) ?
Thanks a lot :)
 
Does the form really need to be created dynamically, or do you just need to populate the controls' values dynamically?

You could try putting the form in a div and setting the div's display property to none. Then it won't show up on the page, but you'll still have it to work with.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 

You can even dispense with the DIV... Just have the form with a style of "display:none;", and use hidden input elements to hold the data.

Hope this helps,
Dan

 
brps's idea will probably work just a well. I don't usually think of a form in terms of something that you put a style attribute on, like a div. I tend to think of it more as an invisible container-type of thing. I'm not sure why that is. I'll have to do some experimenting and see what happens when you treat a form tag like any other block-level tag and apply style attributes to it.

solmyr72: thanks for the comment about the signature. I read it somewhere many years ago and "borrowed" it, changing the word "ketchup" to "mustard" (I don't like ketchup). The original is from Lord of the Rings: "Meddle not in the affairs of dragons, for they are cunning and quick to anger," (or something like that). Another version I like (being a cat person) is: "Meddle not in the affairs of cats, for they are cunning and will pee on your keyboard."


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top