Results 1 to 2 of 2

Thread: dynamic form generation and jquery selectors

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    dynamic form generation and jquery selectors

    I have a form that is dynamically created from a database, that enables or disables appropriate controls in a repeater.

    This is all working fine, but it also needs branching. IE selecting a certain value for a certain field may make another field appear on screen.

    I am not doing the database for this so im limited with chnages I can make on that side of things.

    Basically im passed a table that looks like this: (Ive stripped out the irelevance)

    qid
    InitialStateVisible
    QuestionIDChangeState
    ChangeStateOption
    ChangeStateID

    1 1 NULL NULL NULL
    2 0 1 equal 1
    3 1 NULL NULL NULL
    4 1 NULL NULL NULL
    5 1 NULL NULL NULL

    When loading the repeater Each question is wrapped in a panel, and I set display:none; to the questions where initialstatevisible = false.

    in this scenariop this is QID 2. to find out how this should be visiblity should be toggled we look too QuestionIDChangeState, ChangeStateOption, ChangeStateID

    In this instance QID2 will be shown when qID 1 has a value that equals 1.

    Basicaly what Ive tried is adding classes to the appropriate controls.

    To the hidden div (QID2) I add a class of target2, the radiobuttonlist a calss of changer2 and to the radiobutton list I add a javascript onclick of branching(2,'=',1);"


    the function looks like this

    Code:
     function branching(QID, operator, value) {
    
        var g = $('.changer' + QID).val();
        alert(g);
        
          //$('.target' + QID).show('slow', function() {
           
         // });
    
      }
    basically I need to find the radiobutton list, check its selected value matches the equals then show the div.

    Firstly I cannot get the jQuery right to get the selected value and secondly is this a good way of doing things?

    Thanks for your time.

  2. #2
    King of sapila
    Join Date
    Oct 2006
    Location
    Greece
    Posts
    6,763

    Re: dynamic form generation and jquery selectors

    For the first part, if you id your co9ntrols then you can try $('#changer') if you class them try the control first 'a.changer' .
    ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
    πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width