• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

creating form hidden input on the fly


is it possible to create form hidden input on the fly?

I have a table in which I moved the forms out of the table so the formatting works fine. It all works fine, however as a result, depending on a database open, there may be 10 - 40 foms much like the one below in the html.

In the form below which has a unique name based on the database field, all hidden input elements are always the same for all forms, the only thing that changes is the first hidden input, which has it's value set before form is submitted:

<select onChange="document.frmSearchField2ContactFullName.ContactFullName.value=this.options[this.selectedIndex].value;document.frmSearchField2ContactFullName.submit();">

it all works fine, however there is a lot of forms in the html that have to load.

Is there a way to have a single form and create a hidden field in it right before setting a value to it?

below is the form:

<FORM name=frmSearchField2ContactFullName action="" method=GET>
<input type="hidden" name="ContactFullName" value="">
<input type="hidden" name="fieldname" value="ContactFullName">
<input type="hidden" name="fKeyWords" value="">
<input type="hidden" name="fOrderBy" value="JobIDdesc">
<input type="hidden" name="fMode" value=>
<input type="hidden" name="Table" value=jb_jobs>
<input type="hidden" name="pagesize" value=10>

  • 6
  • 4
1 Solution

Add to <form> tag



<FORM name=frmSearchField2ContactFullName action="" method=GET onsubmit="updateB4submit(this)">

and add the following js function

<script type="text/javascript">
function updateB4submit(thisform){
  thisform.ContactFullName.value = thisform.someselectbox.value;
  return true;

At least I think this is what you are looking for.  You will obviously have to modify the function to draw the value to be set from where ever its coming from.  In your question it sounds a bit like you have more than one form on the page?
995commerceAuthor Commented:
maybe I wasn't clear, yes I have for example 20 forms like this, each identical except for the name and first input:

<input type="hidden" name="ContactFullName" value=""> - from the first example. so the next form could have:

<input type="hidden" name="Contactphone" value="">

and so on. the way it works now the select updates that unique field in the unique form with the selected value before submitting.

so basically I would like to know if I can set up a single form and create a hidden value in it at the same time the option is selected.

995commerceAuthor Commented:
MaxxBlade: what you are proposing is theexact same thing I already have only a lot more complicated.
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

when you say forms do you mean complete forms or just one form with many form elements.
995commerceAuthor Commented:
I'm trying this:

<select onChange="document.formtestspan.innerhtml='<input type=hidden name=JobID value=><input type=hidden name=fieldname value=JobID>';document.formtest.JobID.value=this.options[this.selectedIndex].value;document.formtest.submit();">

and form is:

<FORM name=formtest action="" method=GET><span id=formtestspan></span><input type="hidden" name="fKeyWords" value=""><input type="hidden" name="fOrderBy" value="JobIDdesc"><input type="hidden" name="fMode" value=><input type="hidden" name="Table" value=jb_jobs><input type="hidden" name="pagesize" value=10></form>

could someone point out where is a problem, because it doesn't work
I think I see what you mean now, you want the value of a selection from the selectbox to be sent to a hidden field in another form on the same page and then the form that received the value to be submitted immediatly after?

But just not the value is not being submitted when you change the select box but the form IS being submitted?

I think what's wrong with what you are trying to do is where your are trying to get the value from the select box

you use:


when I think all you need is:


Can i ask why you need to document.innerhtml the extra form fields?  Could you not just add them to the form in the template/html?
995commerceAuthor Commented:
Maxx, could you explain to me why do you answer the question you don't understand and you have no clue what I'm talking about?
OK I'm sorry, I was simply trying to get my head round your problem, forget I asked.
995commerceAuthor Commented:
995commerceAuthor Commented:

I arrived at the solution myself:

<select onChange="document.getElementById('hidField').innerHTML ='<input type=hidden name=JobID value=><input type=hidden name=fieldname value=JobID>';document.formtest.JobID.value=this.options[this.selectedIndex].value;document.formtest.submit();">
Closed, 265 points refunded.

The Experts Exchange
Community Support Moderator of all Ages
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now