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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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

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

chaitu chaituCommented:
$('#hfTest').attr('value', 'abcd');
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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

leakim971PluritechnicianCommented:
With jQuery :

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

Open in new window

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?
zrazakAuthor Commented:
Not completely answered
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!
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.