# Other Languages > jQuery >  JQUERY Help

## aNubies

Okay I'm having a hard time figuring this problem though for others it might be an easy task for them. What im trying to do is put an masking for all my input controls. However, the pattern that will be implemented is base on what the user will select on a dropdownlist. So lets assume that my pattern categories would be:

999-9999
(002) 999-9999

Now when they select one that is the time that the masking will be implemented in the input box. My problem is that when i select one nothing happen.

So here's my code BTW this is just a testing project for me.


MARKUP CODE

    <script type="text/javascript">
        $(document).ready(function(){
            var label = $('#HiddenField1').val();
            $('#TextBox1').mask(label, {placeholder:'_'});
        });

    </script>


CODE BEHIND

Sub Page_Load()
   Me.HiddenField1.value = Me.Session("PATTERN")   
ENd Sub

Dropdownlist1_SelectedTextChanged
   Me.Session("PATTERN") = Me.Dropdownlist1.Text
End Sub

I don't know when jquery execute and how to implement this. Thanks in advance

----------


## Nightwalker83

A better place for this would be in the jquery since the answers could be useful for people use just jquery and not asp.net too.

----------


## si_the_geek

_Thread moved from the 'ASP.Net' forum to the 'jQuery' forum_  (thanks NightWalker  :Thumb:  )

----------


## SambaNeko

The jQuery that you've written will be executed _once_, when the page loads.  If you want some of it to be executed when your drop down changes, then you need to put it in an event handler.


```
<script type="text/javascript">
$(document).ready(function(){
  $('#Dropdownlist1').change(function(){
    //Putting code inside of here assigns it to the 'change' event of #Dropdownlist1
    var label = $('#HiddenField1').val();
    $('#TextBox1').mask(label, {placeholder:'_'});
  }).change(); //putting this here fires the 'change' event once, on page load, to initialize things
});
</script>
```

If this doesn't work as expected, you might want to get rid of the sub Dropdownlist1_SelectedTextChanged and have jQuery handle that functionality instead.

----------


## aNubies

Sorry for the late reply SambaNeko, opeitsnot to late for this though  :Big Grin: .
Well if I'm not mistaken Jqeury will load first in any other events like Button_Click, Dropdownlist_SelectedIndexChange right ? Cause lets say the valueof my dropdownlist iare Type 1, Type 2, Type 3 and when i select one of it it will just  update the hiddenfield on what pattern has been selected. So the hiddenfield willbe updated on the secondpostback right. So how am i going to do that ?

----------


## SambaNeko

Standard disclaimer that ASP's not my forte, but the problem is that your Dropdownlist1_SelectedTextChanged function is only setting Me.Session("PATTERN") to Me.Dropdownlist1.Text, which does _not_ also automatically update the value of HiddenField1, nor does it follow that TextBox1 gets updated either.  You're not binding variables, in other words: each time a change occurs, you have to update everything.

That's what the code I posted accounts for: it's the same code that you've already got in your $(document).ready() function, it just needs to run every time that Dropdownlist1 changes.

Hopefully that both makes sense, and is addressing the right thing.  :Smilie:

----------

