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

x
?
Solved

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

Posted on 2014-08-13
5
Medium Priority
?
173 Views
Last Modified: 2014-08-13
Hi,

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.

Thanks,

 <script type="text/javascript">
$(document).ready(function() { 
    $("div a").click(function() {
        $("#ForMembers,#Coverage,#GenInfo").removeClass("active")
        $(this).closest("div").addClass("active")
        var v = $(this).attr("id");
        $("#recipientId").val(v);
   	if($("#recipientId").val()==6 || $("#recipientId").val()==7 || $("#recipientId").val()==8) {
	$("#contactForm").show();
		}
	else {
		$("#contactForm").hide ();
	}	
    });
});
</script

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

Open in new window

0
Comment
Question by:smfmetro10
  • 2
  • 2
5 Comments
 
LVL 111

Expert Comment

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

Expert Comment

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

Accepted Solution

by:
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"){  
        $("#recipientId").val(param[1]) 
    }  
}  

Open in new window

0
 

Author Comment

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

Author Closing Comment

by:smfmetro10
ID: 40259261
Once again you have saved me!!!
0

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