Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First: as you use <code>jQuery(document).ready()</code> your page is already loaded, when the following code is executed.</p> <p>Second: <code>location.search</code> contains all of the url past th <code>?</code>.<br> To parse it, see <a href="https://stackoverflow.com/q/1403888/1065703">Get escaped URL parameter</a>.</p> <p>To sum it all:</p> <pre><code> &lt;%= javascript_tag do %&gt; function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&amp;|$)').exec(location.search)||[,null])[1] ); } jQuery(document).ready(function () { $(document).on('click', 'a#user', function() { $(".box#input").val($(this).attr('value')); var input = $(".box#input"); $(document).scrollTop(input .offset().top - 45); input.focus(); }); if (getURLParameter('mode')==1) { var input = $(".box#input"); $(document).scrollTop(input .offset().top - 45); input.focus(); } }); &lt;% end %&gt; </code></pre> <p>after all your comments I wrote an example page with your code snippet in it and it works:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt; &lt;title&gt;Insert title here&lt;/title&gt; &lt;script type="text/javascript" src="includes_js/jquery.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" language="javascript"&gt; function getURLParameter(name) { return decodeURI( (RegExp(name + '=' + '(.+?)(&amp;|$)').exec(location.search)||[,null])[1] ); }; jQuery(document).ready(function () { // alert(location.search); var mode=getURLParameter('mode'); // alert(mode); if (mode==1) { var input = $(".box#input"); $(document).scrollTop(input .offset().top - 45); input.focus(); } }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form&gt; &lt;input name="t1" /&gt;&lt;br&gt; &lt;input name="t2" class="box" id="input" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>For me, your selector is pretty strange. Do you really have a tag with <code>class="box" id="input"</code>? Espessially the id seems strange to me.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload