Reputation: 43
I have dropdown box in which i am selecting a value and entering the values in textboxes(For example: i selected 2nd floor and entering respective values in 3 textboxes and again 3rd floor and respective values and so on,finally both should get append.Luckily i am getting this).But the problem is whenever i change the textbox values it should overwrite to the same dropdown values but it is saving previous and present values of textbox(Example: If i select 5th flooor and write values in textboxes and if i change it again it is not overwriting instead of this its saving twice with same values). Please help me in resolving the issue. http://jsfiddle.net/ztord9py/13/
var areaoffered=[];
var floor=[];
var timeline=[];
var floorss;
$("#floor").change(function(){
floorss = $("#floor").val();
});
$("#areaoffered").change(function(){
var areamax = $("#areaoffered").val();
var areamin = (floorss+"-"+areamax);
areaoffered.push(areamin);
});
$("#components").change(function(){
var componentsmax = $("#components").val();
var componentsmin = (floorss+"-"+componentsmax);
floor.push(componentsmin);
});
$("#timeline").change(function(){
var timelinemax = $("#timeline").val();
var timelinemin = (floorss+"-"+timelinemax);
timeline.push(timelinemin);
});
$("#submitt").click(function(){
alert(areaoffered);
});
<select id="floor" >
<option value="1st floor">1st floor </option>
<option value="2nd floor">2nd floor</option>
<option value="3rd floor">3rd floor</option>
<option value="4th floor">4th floor</option>
<option value="5th floor">5th floor</option>
</select></br>
<input type="text" id="areaoffered" /></br>
<input type="text" id="components" /></br>
<input type="text" id="timeline" /></br>
<input type="button" value="Submit" id="submitt" />
Upvotes: 0
Views: 160
Reputation: 43
Myself found an answer
var floors = [];
var timelines=[];
var areas=[];
var components = [];
$("#floor").change(function(){
$("#areaoffered").val(areas[$("#floor").val()]);
$("#components").val(components[$("#floor").val()]);
$("#timeline").val(timelines[$("#floor").val()]);
});
$("#areaoffered").change(function(){
var areaOffered = $("#areaoffered").val();
areas[$("#floor").val()] = areaOffered;
});
$("#components").change(function(){
var componentsmax = $("#components").val();
components[$("#floor").val()] = componentsmax ;
});
$("#timeline").change(function(){
var timelinemax = $("#timeline").val();
timelines[$("#floor").val()]=timelinemax;
});
$("#submitt").click(function(){
var finalDetails = [];
for(var i=1;i<16;i++)
{
if(areas[i]!=undefined)
finalDetails.push('floor:'+i+' areaOffered:'+areas[i]+' components:'+components[i]);
}
alert(finalDetails);
});
Upvotes: 0
Reputation: 1484
replace line inside $("#floor").change();
var floorss={};
$("#floor").change(function(){
floorss[$("#floor").val()] = $("#floor").val();
});
Upvotes: 1