Answered by:
Get value from value selected & split url string

Question
-
User1324715958 posted
I have a couple questions. I need to get the value that the user selected from y auto complete drop down list and I need to split a url. I have a split setup currently but its still wanting to grab the entire url. I need it to "drop off" after it finds the first instance of "/eweb/" Anything after that I dont want in my string.
code:
function populate() { //$("#edit-search-api-fulltext").autocomplete({ source: DataList }); $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { var ui_item = $(this).val(ui.item.value); var location = window.location.href.split("/eweb/"); var url = location + "DynamicPage.aspx?WebCode=ProdSearch&q=" + ui_item; window.location.href = url; console.log(ui_item); console.log("Location: " + location); } }); }
Wednesday, March 20, 2019 4:47 PM
Answers
-
User1324715958 posted
Here is the answer:
function populate() { $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { var searchNow = $("#edit-submit-aha-search"); searchNow.click(); } }); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 20, 2019 7:34 PM -
User1324715958 posted
a better fix/solution
function populate() { $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { $("#edit-search-api-fulltext").val(ui.item.value); var searchButton = $("#edit-submit-aha-search"); searchButton.click(); } }); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 21, 2019 4:22 PM
All replies
-
User475983607 posted
I have a couple questions. I need to get the value that the user selected from y auto complete drop down list and I need to split a url. I have a split setup currently but its still wanting to grab the entire url. I need it to "drop off" after it finds the first instance of "/eweb/" Anything after that I dont want in my string.
code:
function populate() { //$("#edit-search-api-fulltext").autocomplete({ source: DataList }); $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { var ui_item = $(this).val(ui.item.value); var location = window.location.href.split("/eweb/"); var url = location + "DynamicPage.aspx?WebCode=ProdSearch&q=" + ui_item; window.location.href = url; console.log(ui_item); console.log("Location: " + location); } }); }
Please take a moment to use the browser's dev tools (F12) to debug your code.
var ui_item = "1"; var url = "http://forums.asp.net/eweb/some/folder/page.aspx"; var loc = url.split("/eweb/"); console.log(loc[0]); var newUrl = loc[0] + "/DynamicPage.aspx?WebCode=ProdSearch&q=" + ui_item; console.log(newUrl);
Results
http://forums.asp.net/DynamicPage.aspx?WebCode=ProdSearch&q=1
Wednesday, March 20, 2019 4:58 PM -
User1324715958 posted
I got everything working except my split:
function populate() { //$("#edit-search-api-fulltext").autocomplete({ source: DataList }); $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { var searchText = ui.item.value; var location = window.location.href.split("/eweb/")[0]; var url = location + "DynamicPage.aspx?WebCode=ProdSearch&q=" + searchText; window.location.href = url; console.log("search item: " + searchText); console.log("Location: " + location); } }); }
On the first run the url works:
On the second run is when it starts to fail:
I just want "http://dev.aha.local/eWeb/" everytime. The trick is "http://dev.aha.local/" this part may change pending on what environment I'm testing in but I need it to grab everything up until after "/eWeb/" which is appears to not be doing that currently.
Wednesday, March 20, 2019 5:50 PM -
User475983607 posted
The logic is very difficult to understand. location is a JavaScript object, I would change the variable name to loc or something else.
The current page is refreshed every time an autocomplete item is selected. The first time through /eweb/ is removed and the two console.log() lines don't matter much as you probably cannot see anything. From there it is not clear what page is displayed in the browser but /eweb/ no longer exists. Therefore the split will return the entire URL.
I strongly recommend that setting a break point using Dev Tools to make sure your logic is functioning as expected.
Wednesday, March 20, 2019 6:17 PM -
User1324715958 posted
Here is the answer:
function populate() { $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { var searchNow = $("#edit-submit-aha-search"); searchNow.click(); } }); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, March 20, 2019 7:34 PM -
User839733648 posted
Hi UOKSoftware,
I suggest that you coud mark your solution as answer if it solved your problem.
And this will be helpful to someone meets with the same problem.
Best Regards,
Jenifer
Thursday, March 21, 2019 8:54 AM -
User1324715958 posted
a better fix/solution
function populate() { $("#edit-search-api-fulltext").autocomplete({ source: DataList, select: function (event, ui) { $("#edit-search-api-fulltext").val(ui.item.value); var searchButton = $("#edit-submit-aha-search"); searchButton.click(); } }); }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, March 21, 2019 4:22 PM