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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create HIDDEN input on Form Dynamically 2

Status
Not open for further replies.

bont

Programmer
Sep 7, 2000
200
US
I have a form, that has about 100 fields. It currently has no hidden inputs within it. When I hit the submit button, I would like to call a javascript function which will:

1) Dynamically create 100 hidden fields

2) After I pupulate them, I would like to submit to another page.

This makes it difficult for the user to see it, and makes the page smaller in file size.

I have the change page done. How do I create a new form element. I would think I could do something like:

document.add.input

Then set the settings. It is the call to create the element and then apply it, that I don't know.

Any help would be appreciated.
 
Why do u want to create hidden elements to send data from the form. You have the form elements which is sent when u post the form...

If u still wanna do it...
Create the hidden elements when u form the HTML itself. Now u have the HTML painted with the regular form as well as Hidden elements. Now just assign values to the hidden elements in Javascript and then submit

 
I want to maximize efficientcy. Download time is scarce. If I do not create the <input type=&quot;hidde&quot;... tags prior to download, and do everything clientside, I will save a lot of download time. My form will have NO hidden to start. When they hit submitt, I will create X amount of hidden inputs, and set them. Allowing me to then pass the values to the next page. Is there a way to do this using NEW?
 
<script>
function makehidden(){
var i = 0;
var objDiv = document.getElementById(&quot;hiddenFieldsContainer&quot;);
var arrContent = new Array();
while(i<101){
arrContent[arrContent.length] = &quot;<input type=\&quot;text\&quot; name=\&quot;text&quot;;
arrContent[arrContent.length] = i.toString();
arrContent[arrContent.length] = &quot;\&quot; value=\&quot;this is textbox named: text&quot;;
arrContent[arrContent.length] = i.toString();
arrContent[arrContent.length] = &quot;\&quot; style=\&quot;width:300\&quot;><br>&quot;;
i++;
}
objDiv.innerHTML = arrContent.join(&quot;&quot;);
}
</script>
<form action=&quot;mypage.asp&quot; onsubmit=&quot;return makehidden();&quot;>
<input type=submit>
<div id=&quot;hiddenFieldsContainer&quot;>
</div>
</form>
 
OK,

2 questions:

1) Do I have to use a container in this fashion, I just can't create a new reference of them?

2) Will this DIV idea work, being that the form is already in a DIV?
 
1. I think there are other ways but I only know this one.

2. Tested with IE and submitted to asp, no problem all the textbox or hidden items were in the request(&quot;text&quot; & number)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top