-
Nov 13th, 2011, 10:09 PM
#1
Thread Starter
Fanatic Member
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
-
Nov 14th, 2011, 12:14 AM
#2
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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Nov 14th, 2011, 06:59 AM
#3
Re: JQUERY Help
Thread moved from the 'ASP.Net' forum to the 'jQuery' forum (thanks NightWalker )
-
Nov 14th, 2011, 01:37 PM
#4
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.
-
Nov 18th, 2011, 03:25 AM
#5
Thread Starter
Fanatic Member
Re: JQUERY Help
Sorry for the late reply SambaNeko, opeitsnot to late for this though .
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 ?
-
Nov 18th, 2011, 12:50 PM
#6
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|