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

creating form hidden input on the fly

Hi,

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>
</form>


TIA
0
995commerce
Asked:
995commerce
  • 6
  • 4
1 Solution
 
MaxxBladeCommented:
try...

Add to <form> tag

onsubmit="updateB4submit(this)"

ie.

<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?
0
 
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.


0
 
995commerceAuthor Commented:
MaxxBlade: what you are proposing is theexact same thing I already have only a lot more complicated.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
MaxxBladeCommented:
when you say forms do you mean complete forms or just one form with many form elements.
0
 
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
0
 
MaxxBladeCommented:
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:

this.options[this.selectedIndex].value

when I think all you need is:

this.value

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?
0
 
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?
0
 
MaxxBladeCommented:
OK I'm sorry, I was simply trying to get my head round your problem, forget I asked.
0
 
995commerceAuthor Commented:
done
0
 
995commerceAuthor Commented:
ok,

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();">
0
 
GranModCommented:
Closed, 265 points refunded.

GranMod
The Experts Exchange
Community Support Moderator of all Ages
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

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