-
JQUERY Help
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
-
Re: JQUERY Help
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.
-
Re: JQUERY Help
Thread moved from the 'ASP.Net' forum to the 'jQuery' forum (thanks NightWalker :thumb: )
-
Re: JQUERY Help
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.
Code:
<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.
-
Re: JQUERY Help
Sorry for the late reply SambaNeko, opeitsnot to late for this though :D.
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 ?
-
Re: JQUERY Help
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. :)