I have a table that two of the columns are "other" fields, that the user then sets what those values are if they decide to enter data in that column. Currently how I have accommodated this is that under the table I have two single line fields that "show" only if data is entered into their corresponding column. However, I would like to embed those description fields into the column header. Is there a way to do this?
Question
Question
Is there a way to insert an input field into a table header?
Answer
I found a way to get the two input fields into their respective table headers.
This what I have for the JavaScript:
//Find the controls var txtTargetOne = $('#otherInputOneNewLocation'); var txtTargetTwo = $('#otherInputTwoNewLocation'); //Search for DIV, INPUT or SPAN, SPAN is used for display var txtFieldOne = $('.otherInputOne DIV.cf-field DIV, .otherInputOne DIV.cf-field INPUT, .otherInputOne DIV.cf-field SPAN'); var txtFieldTwo = $('.otherInputTwo DIV.cf-field DIV, .otherInputTwo DIV.cf-field INPUT, .otherInputTwo DIV.cf-field SPAN'); //Remove the textbox from its current location txtFieldOne.remove(); txtFieldTwo.remove(); //Insert textbox after the place holder/target txtFieldOne.insertAfter(txtTargetOne); txtFieldTwo.insertAfter(txtTargetTwo); //Remove the place holder/target txtTargetOne.remove(); txtTargetTwo.remove(); //Hide the old label $('.otherInputOne').hide(); $('.otherInputTwo').hide();
Then in the column labels I entered the following.
<div id="otherInputOneNewLocation">Other 1 Amount</div>(2)
<div id="otherInputTwoNewLocation">Other 2 Amount</div>(2)
'otherInputOne' and 'otherInputTwo' are the CSS Class names of the input fields being moved.
This is the answer that gave me the hints on how to get it to work : https://answers.laserfiche.com/questions/64063/Answer-Using-DIV-to-place-storeable-input-fields-into-HTML-text-blocks#82402
Replies
You could try the following:
Where "#Field1" is the id of the description input and "Field3(1)" is the id of the target column header.
$(function(){ $('#Field1').change(function(){ $('th > label[for="Field3(1)"]').text($(this).val()); }) })
The following is my code, and it does the first alert (got here 3) but must error out on the line after that because it does not get to the second alert (got here 4). "otherInputOne" is the class name of my input field. Any ideas what I might be missing?
$(function(){ $('.otherInputOne input').change(function(){ $(this).val(); alert("got here 3"); $('th > label[for="q92(1)"]').text(desc); alert("got here 4"); }) })
Try the following:
$(function(){ $('.otherInputOne').change(function(){ $('th > label[for="Field92(1)"]').text($(this).val()); }); $('.otherInputTwo').change(function(){ $('th > label[for="Field94(1)"]').text($(this).val()); }) })
You dont need the # as that is only for ids. Please try the updated code above.
I had to remove the '#" to get it to put the input from the field into the table label. And I think it is rather slick and may be what we end up doing. However what I was wanting to do was to make it so a user could type within the table label. My team thinks that having the fields below the table (as I have them now) would be a bit confusing to our end users.
Labels are not really intended for user input, but your colleagues are probably correct and this may end up being confusing to your end users.
I might suggest instead adding a "Description" column next to each "Other Amount" it with an input for describing what the other amount is for. I think this might be less confusing.
I found a way to get the two input fields into their respective table headers.
This what I have for the JavaScript:
//Find the controls var txtTargetOne = $('#otherInputOneNewLocation'); var txtTargetTwo = $('#otherInputTwoNewLocation'); //Search for DIV, INPUT or SPAN, SPAN is used for display var txtFieldOne = $('.otherInputOne DIV.cf-field DIV, .otherInputOne DIV.cf-field INPUT, .otherInputOne DIV.cf-field SPAN'); var txtFieldTwo = $('.otherInputTwo DIV.cf-field DIV, .otherInputTwo DIV.cf-field INPUT, .otherInputTwo DIV.cf-field SPAN'); //Remove the textbox from its current location txtFieldOne.remove(); txtFieldTwo.remove(); //Insert textbox after the place holder/target txtFieldOne.insertAfter(txtTargetOne); txtFieldTwo.insertAfter(txtTargetTwo); //Remove the place holder/target txtTargetOne.remove(); txtTargetTwo.remove(); //Hide the old label $('.otherInputOne').hide(); $('.otherInputTwo').hide();
Then in the column labels I entered the following.
<div id="otherInputOneNewLocation">Other 1 Amount</div>(2)
<div id="otherInputTwoNewLocation">Other 2 Amount</div>(2)
'otherInputOne' and 'otherInputTwo' are the CSS Class names of the input fields being moved.
This is the answer that gave me the hints on how to get it to work : https://answers.laserfiche.com/questions/64063/Answer-Using-DIV-to-place-storeable-input-fields-into-HTML-text-blocks#82402