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


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

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Do you have a server-side scripting language available such as PHP or ASP, etc.?
Why not just do this server side?
It's more complicated using js for this at the client.
If you must do it client side then

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

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
smfmetro10Author Commented:
Yeah... The server side language is idoc script.... which I can't figure out :)
smfmetro10Author Commented:
Once again you have saved me!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.