JQUERY Help-VBForums
Results 1 to 6 of 6

Thread: JQUERY Help

  1. #1

    Thread Starter
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    521

    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

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    12,980

    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.
    Please consider giving me some rep points if I help you a lot.
    Links to my code examples can now be found on my website: My websites
    Please rate my post if you find it helpful!
    Technology is a dangerous thing in the hands of an idiot! I am that idiot.

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    37,163

    Re: JQUERY Help

    Thread moved from the 'ASP.Net' forum to the 'jQuery' forum (thanks NightWalker )

  4. #4
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,504

    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.

  5. #5

    Thread Starter
    Fanatic Member aNubies's Avatar
    Join Date
    Aug 2008
    Posts
    521

    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 ?

  6. #6
    Frenzied Member
    Join Date
    Apr 2009
    Location
    CA, USA
    Posts
    1,504

    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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.