[Webinar] Learn how to a build a cloud-first strategyRegister Now


How do you assign a value to a hidden input field based on a url parameter using jquery

Posted on 2014-08-13
Medium Priority
Last Modified: 2014-08-13

I have a function that will change the value of a hidden input based on an <a> click.

What I would like to have, is first the hidden field getting a value assigned to it based on a URL parameter.  The URl will have "subjectId=" with a number assigned to it..... ( So, it could be subjectId=7.... and the hidden input (recipientId) will have a value assigned to it when the page loads.

Here is what I have so far.


 <script type="text/javascript">
$(document).ready(function() { 
    $("div a").click(function() {
        var v = $(this).attr("id");
   	if($("#recipientId").val()==6 || $("#recipientId").val()==7 || $("#recipientId").val()==8) {
	else {
		$("#contactForm").hide ();

<input type="hidden" id="recipientId" name="recipientId" value=""  />

Open in new window

Question by:smfmetro10
  • 2
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 40259217
Do you have a server-side scripting language available such as PHP or ASP, etc.?
LVL 58

Expert Comment

ID: 40259218
Why not just do this server side?
It's more complicated using js for this at the client.
LVL 58

Accepted Solution

Gary earned 2000 total points
ID: 40259242
If you must do it client side then

url = window.location.search.substring(1);  
urlvars = url.split('&');  
for (i = 0; i < urlvars.length; i++){  
    param = urlvars[i].split('=');  
    if (param[0] == "subjectId"){  

Open in new window


Author Comment

ID: 40259247
Yeah... The server side language is idoc script.... which I can't figure out :)

Author Closing Comment

ID: 40259261
Once again you have saved me!!!

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question