Change Value of hidden field

I have javascript to test screen size and choose style sheet and defined a string variable in javascript.  No I want to set the value of an asp.net
hidden control with the appropriate screen value .  Any help with code is appreciated.
<script type="text/javascript" language="javascript">
          
         $(document).ready(function() {

            if (screen.width < 480) {
                $('.basicStyles0').attr('href', "css/main.css");
                var a = "desktop";
                
            }
           
            else {
                $('.basicStyles0').attr('href', "css/mobile_main.css");
                var b = "mobile";
            }
        });
    
    
    </script>

Open in new window

<asp:HiddenField ID="hfTest" value="" runat="server" />

Open in new window

zrazakAsked:
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.

BadotzCommented:
Instead of
var a = "desktop";

Open in new window

try
[document.getElementById("hfTest").value = "desktop";

Open in new window

0

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
BadotzCommented:
Omit that leading "["
document.getElementById("hfTest").value = "desktop";

Open in new window

0
chaitu chaituCommented:
$('#hfTest').attr('value', 'abcd');
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Imran Javed ZiaConsultant Software Engineer - .NET ArchitectCommented:
Hi,
you can use attached code

$(document).ready(function() {  
  
            if (screen.width < 480) {  
                $('.basicStyles0').attr('href', "css/main.css");  
                var a = "desktop";  
                document.getElementById('<%= hfTest%>').value = a;
                  
            }  
             
            else {  
                $('.basicStyles0').attr('href', "css/mobile_main.css");  
                var b = "mobile";  
                document.getElementById('<%= hfTest%>').value = b;
            }  
        });

Open in new window

0
leakim971PluritechnicianCommented:
With jQuery :

$("#<%= hfTest.ClientID %>").val( b );

Open in new window

0
zrazakAuthor Commented:
How can i see if the value is actually stored in hidden field can it be called from the code behind and stored in a regular label?
0
zrazakAuthor Commented:
Not completely answered
0
BadotzCommented:
>>Not completely answered

What was not completely answered?

If that is indeed the case, then why did you close the question? Why did you not respond to the suggestions?

Whatever we may be, we are not mind readers. If you are not satisfied, SAY SO!
0
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
JScript

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.