# Javascript help

**URL:** <https://forums.knack.com/t/javascript-help/14806>\
**Category:** Get Answers\
**Created:** [September 4, 2023, 4:01pm UTC](https://forums.knack.com/t/javascript-help/14806 "2023-09-04T16:01:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris8](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@Chris8](https://forums.knack.com/u/Chris8)\
**Post date:** [September 4, 2023, 4:01pm UTC](https://forums.knack.com/t/javascript-help/14806/1 "2023-09-04T16:01:56Z")

</div>

Hi all,

Im hoping someone can help me with this bit of javascript. I have two search views onb one page and want the user to only search in 1 and have the other search update. So far i have this:

```auto
$(document).on('knack-records-render.view_203', function(event, view, records) {
  
    var e = document.getElementById("kn-conn-1-field_142");
    var siteSearch = e.options[e.selectedIndex].text;
    var f = document.getElementById("value");

  //alert('you have searched for ' + siteSearch);

    $('#view_227-field_2').text(siteSearch);
    $('#view_227-field_2').view;

  console.log(siteSearch);

});

```

However i cant seem to get the second view to receive the sitesearch info. Any help is much appreciated.

---

<div class="post-metadata">

**Author:** ![Chris8](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@Chris8](https://forums.knack.com/u/Chris8)\
**Post date:** [September 7, 2023, 3:35pm UTC](https://forums.knack.com/t/javascript-help/14806/2 "2023-09-07T15:35:20Z")

</div>

the get element by id also appears to be broken, in that it works the first time i load the page, but if i navigate to a different page and back, it fails. I assume this is because it will get a different ID, but im not sure how to get the searched item.

---

<div class="post-metadata">

**Author:** ![Chris8](https://avatars.discourse-cdn.com/v4/letter/c/e56c9b/32.png) [@Chris8](https://forums.knack.com/u/Chris8)\
**Post date:** [September 15, 2023, 7:46pm UTC](https://forums.knack.com/t/javascript-help/14806/3 "2023-09-15T19:46:51Z")

</div>

Okay so i think i have cracked this sort of…

i use this code to hide the second search i dont want visible:

```auto
//hides the search
$(document).on('knack-scene-render.scene_34', function(event, scene) {

  var $elementToHide = $("#view_227 > form > div.kn-submit.control.is-horizontal");
  $elementToHide.css('visibility', 'hidden');
  $("#view_227-search").css('visibility', 'hidden');

});

```

then i use this code to grab the searched item and send it to the second search box:

```auto
$(document).on('knack-records-render.view_203 , knack-records-render.view_200 , knack-records-render.view_201', async function(event, view, records) {

  Knack.showSpinner();

  // Find the dropdown element by its attributes or position in the DOM.
  var $dropdown = $('[data-field-key="field_142"]');

  if ($dropdown.length > 0) {
  // Get the selected option text from the dropdown.
  var siteSearch = $dropdown.find('option:selected').text();

  console.log(siteSearch);

  $("input[name='value']").val(siteSearch);
  $("input[name='value']").submit();

  Knack.hideSpinner();
});

```

This seem to be working okay. Its probably not the best way to do it, but it works for me. Hopefully it will help someone else… maybe
