Link to home
Start Free TrialLog in
Avatar of 995commerce
995commerce

asked on

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
Avatar of MaxxBlade
MaxxBlade

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?
Avatar of 995commerce

ASKER

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.


MaxxBlade: what you are proposing is theexact same thing I already have only a lot more complicated.
when you say forms do you mean complete forms or just one form with many form elements.
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:

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?
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.
done
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();">
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial