Help please, I am not quite sure how to approach this one:
I have an app where the client has several sections which contain several fields. Sometimes the same field appears. For example, “quantity” or “color” may appear in three, four or more sections.
When the web form is submitted, the value sent to the other end is empty because the next qty field, which is empty, will overwrite the value, thus producing an empty/null value on the other end. [there is only one quantity field on the other end]
Because of the structure of this app, which they want to maintain, I want a clear cut way of saying/do the following using jquery:
get fields #quantityOne,#quantityTwo,#quantityThree, determine which one has a value in it, take that value and place it in hidden field finalQty.
Could someone show me how to accomplish this please?
Adding one note for clarification:
The user would only be filling out ONE of the sections, thus only one
of the qty fields. So if I put 555 in qtyField #1, then 555 should be
copied to finalQty, if I put 35 in qtyField #2, then 35 should be
copied to finalQty
html/jquery:
<fieldset id="sectionOne" name="sectionOne">
<legend class='legendHdrs' >Section One</legend>
Name: <input type="text" name="nameOne" id="nameOne" class="name" /><br />
Quantity: <input type="text" name="quantityOne" id="quantityOne" class="quantity"/>
</fieldset><br /><br />
<fieldset id="sectionTwo">
<legend>Section Two</legend>
Name: <input type="text" name="nameTwo" id="nameTwo" class="name" /><br />
Quantity: <input type="text" name="quantityTwo" id="quantityTwo" class="quantity"/>
</fieldset><br /><br />
<fieldset id="sectionThree">
<legend>Section Three</legend>
Name: <input type="text" name="nameThree" id="nameThree" class="name" /><br />
Quantity: <input type="text" name="quantityThree" id="quantityThree" class="quantity"/>
</fieldset>
<hr>
Final Qty: <input type="text" name="finalQty" id="finalQty" class="finalQty"/>
<input type="button" value="Add Qty" id="addQty">
</form>
$(document).ready(function()
{
$('#addQty').on('click', function()
{
var holdval;
$('#quantityOne,#quantityTwo,#quantityThree').each(function()
{
if($(this).val() !== '')
{
holdval = $(this).val()
}
});
$('#finalQty').val(holdval);
});
});
According to edit