Advertisement
abdullahakram808

Jquery query string value

May 26th, 2020
1,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.07 KB | None | 0 0
  1. <p class="lead">Add a "?q=XXXX" at the end of the URL and you will see the value here.</p>
  2. <b>Value: <span id="insert-value">UNDEFINED</span></b>
  3.  
  4. </br></br></br>
  5. I would rather the value in the input and disappear when you click the input</br>
  6. <input type='text' name='q' id='searchthat' class='custom_input_inside message'>
  7.  
  8. <script src="jquery-3.4.1.min.js"></script>
  9. <script src="https://code.jquery.com/jquery-3.2.1.slim.js"/></script>
  10.     <script>
  11. !(function (e) {
  12.     e.extend({
  13.         uriGet: function () {
  14.             var e = location.href,
  15.                 t = new URL(e),
  16.                 n = t.searchParams.get(arguments[0]);
  17.             return n;
  18.         },
  19.     });
  20. })(jQuery);
  21.  
  22.     $( document ).ready(function() {
  23.       var a = $.uriGet('q');
  24.       $('span#insert-value').html(a);//if you change that to input it wont work.  I want it to triggure in the input field only would be better if it will by css in the input
  25.     let inputEle = $("#searchthat");
  26.     inputEle.val(a);
  27.     inputEle.on("focus",function(){
  28.       inputEle.val("");
  29.     });
  30.  
  31.   });
  32.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement