how to get value from url parameter using javascript or jquery -
i have issue in getting value url, have link shows modal have
<a href='#modal?userid=<%=resultset.getint("drid")%>' class="button-border togglemodal">apportionment</a>
above link opens modal given below
<div id="modal" class="modal"> <header> <h2>appointment form</h2> </header> <form action="addappoinment.jsp" method="post"> <input type="hidden" id="docid" name="docid" value=""><br> <input type="text" required><br> <input type="text" required><br> <input type="text" required><br> <input type="text" required><br> <textarea rows="4" cols="21"></textarea><br> <button class="button-border button-success" type="submit"> done</button> <button class="button-border button-error pull-right togglemodal"> cancel</button> </form> </div>
now have url
http://localhost:8080/app/#modal?userid=1
now want value of userid
parameter using javascript
<script type="text/javascript"> function getparameterbyname(name) { name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); var regex = new regexp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(location.search); return results === null ? "" : decodeuricomponent(results[1].replace(/\+/g, " ")); } var param = getparameterbyname("userid"); var userid = document.getelementbyid("docid"); userid.value = param; </script>
but can not able value http://localhost:8080/app/#modal?userid=1
#modal?userid=1
the query string (which sent server) has go before fragment identifier (which handled entirely client side).
i.e.
?userid=1#modal
if don't want send data server, need read fragment identifier (location.hash
) , split on ?
piece need.
Comments
Post a Comment