Pass value returned from jqueryui autocomplete to another function
Here's my use case: User selects an option returned from an autocomplete lookup. Data returned from the lookup is assigned to a number of other input boxes on the form. Further into the form, user gets to a select box where they choose a "Link type." The selection of a link type triggers a 2nd function which assigns some default values, such as boilerplate text for the link descriptions, to some related input boxes.
Question: How would I pass a value selected from my autocomplete 开发者_Python百科function to my 2nd function?
Here's the autocomplete code:
$('#chooseChannel').val("");
$('#chooseHLProgName').val("");
$("#chooseHLProgName").autocomplete({
source: function( request, response ) {
$.getJSON( '/test/myCFC.cfc?', {
method: 'qryMyMethod',
returnformat: 'json',
searchTerm: request.term,
dsn: 'myDSN',
virtChannel: $('#chooseChannel').val()
}, response );
},
minLength: 3,
select: function(event,ui) {
$('#seriesID').val(ui.item.seriesid),
$('#versionID').val(ui.item.versionid),
$('#channel').val($ ('#chooseChannel').val() ),
$('#chooseHLTitle').val(ui.item.progFullTitle),
$('#chooseHLDesc').val(ui.item.progDesc),
$('#chooseHLDateTimeInfo').val(ui.item.progDateTime),
$('#setScheduleURL').val('/schedules/listingDetails.cfm?seriesID=' + ui.item.seriesid + '&versionID=' + ui.item.versionid + '&virtChannel=' + $('#chooseChannel').val() + '&ThisDate=' + ui.item.progDate) // This is the value I want to use in another function
}
});
I need the value that's currently being assigned (inside the autocomplete) to the static #setScheduleURL hidden field to instead be passed to the function below. Specifically, when a user chooses <option value="scheduleLink">Link to schedule</option>
from <select name="chooseHLLinkType1" id="chooseHLLinkType1">
, I want the value assigned to #setScheduleURL (in the autocomplete) passed to the case option, $('input[name^=inputLinkURL'+ selectNum + ']').val( VALUE OF #SETSCHEDULEURL );
Here's the 2nd function:
// insert default text strings into input boxes based on value of selected 'chooseHLLinkType' option
$('select[name^=chooseHLLinkType]').change(function() {
var selectValue = $(this).val();
var selectNum = $(this).attr("id").charAt($(this).attr("id").length-1);
switch(selectValue) {
case 'webLink' :selectValue='Visit website';
$('input[name=inputLinkText'+ selectNum + ']').val( selectValue );break;
case 'videoLink' :selectValue='View Preview';
$('input[name^=inputLinkText'+ selectNum + ']').val( selectValue );break;
case 'scheduleLink' :selectValue='View schedule';
$('select[name^=inputLinkLoc'+ selectNum + ']').val( 'internal' );
$('input[name^=inputLinkURL'+ selectNum + ']').val( VALUE OF #SETSCHEDULEURL );
$('input[name^=inputLinkText'+ selectNum + ']').val( selectValue );break;
case 'customLink' :selectValue='';
$('input[name^=inputLinkText'+ selectNum + ']').val( selectValue );break;
}
});
And here's the relevant portion of the html. Note: dynamic ids are assigned because this set of related form fields (chooseHLLinkType, inputLinkLoc, inputLinkURL, inputLinkText) can be cloned.
<div id='clonedSection1' class='clonedSection'>
<p><label for="chooseHLLinkType1" id="chooseHLLinkTypeLabel1">Related Info Type<br />
<cfselect name="chooseHLLinkType1" id="chooseHLLinkType1">
<option value="none">-SELECT ONE-</option>
<option value="webLink">Website link</option>
<option value="videoLink">Link to video</option>
<option value="scheduleLink">Link to schedule</option>
<option value="customLink">Custom link</option>
</cfselect>
</label></p>
<p><label for="inputLinkLoc1" id="inputLinkLocLabel1">Link Location<br />
<cfselect name="inputLinkLoc1" id="inputLinkLoc1">
<option value="none">-SELECT ONE-</option>
<option value="internal">Internal: it's on our site</option>
<option value="external">External: it's out on the World Wild Web</option>
</cfselect>
</label></p>
<p><label for="inputLinkURL1" id="inputLinkURLLabel1">Link URL<br />
<cfinput type="text" name="inputLinkURL1" id="inputLinkURL1" size="50" />
</label></p>
<p><label for="inputLinkText1" id="inputLinkTextLabel1">Link text<br />
<cfinput name="inputLinkText1" id="inputLinkText1" size="20" maxlength="13" required="no" />
</label></p>
</div>
Nothing I've tried so far has worked. Thank you for your suggestions.
You can access the value of #setScheduleURL like this:
$('#setScheduleURL').val()
精彩评论