Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created the textbox in infopath ,Here I have used auto suggest control for a textbox, I will load value and ID in that text box , on selecting a value in auto suggest on the textbox an id will be generated for that selected value, I need to store that is in another text box,on post back the stored ID is getting cleared in that text box is there any solution for this.

JavaScript
window.onload = function() {
window.setTimeout(getData, 1000);
}

function getData(){
getState();
window.setTimeout(getData, 1000); //To handle IP's form postback
}


function getState(){ 
var state = []; 
$().SPServices({ 
operation: "GetListItems", 
listName: "state",
CAMLViewFields: "", 
async: false, 
completefunc: function (xData, Status) { 
$(xData.responseXML).SPFilterNode("z:row").each(function() { 
state.push({label:$(this).attr("ows_Column2"),value:$(this).attr("ows_ID")});   
}); 
} 
}); 

$("input[id$='FormControl0_V1_I1_T22']").autocomplete({ 
source: state, 
minLength: 2, 
change: function (event, ui) {
},

select: function( event, ui) {
alert(ui.item ? ("You picked '" + ui.item.label + "' with an ID of " + ui.item.value) : "Nothing selected, input was " + this.value);

$("input[id$='FormControl0_V1_I1_T22']").val(ui.item.label);
$("input[id$='FormControl0_V1_I1_T23']").val(ui.item.value);
                return false;
        },

focus: function(event, ui){
event.preventDefault();
$("input[id$='FormControl0_V1_I1_T22']").val(ui.item.label);
          return false;
        }
});
}


Thanks in advance.
Posted
Updated 23-Jan-14 0:40am
v3

1 solution

When you type something in to a text box and then reload the page, you need to populate the text box on the server explicitly, or the value will be lost. Using AJAX to make your requests, sidesteps this issue, otherwise, you WILL lose your values, unless you write code to deal with that.
 
Share this answer
 
Comments
A. Ramkumar 24-Jan-14 3:32am    
Can you specify me the Ajax code as example
Christian Graus 24-Jan-14 3:34am    
No, that's actually not possible. I don't know what you're trying to do. You can read the jquery docs on how to make an AJAX call from your page in general, but I don't know what call you want to make

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900