1

I have been trying to call a javascript function within a jquery dialog box, which I have been successful at. The complication comes when I create a dynamic form within the dialog box by passing in data from a listbox to a php page that calls the database. I am trying to first, disable the second dropdown when a value in the first dropdown is selected. Secondly, I would like to validate a textbox to see if a username exists.

I have created a JSbin http://jsbin.com/etuhur/4/edit but I am not sure how to replicate the PHP portions. The current JSbin is working in regards to the first dropdown disabling the second dropdown. I am unable to replicate this functionality when the form is created by a php page that I pass into the dialog box.

Does anyone have any tips, pointers or an example? I have been trying to get this to work for the past two weeks, but to no avail :(

EDIT : I think it has something to do with the DOM not recognizing the PHP form data being created by another page, does anyone know how I would have it register with the DOM?

4
  • so u copy html first and then paste it into dialog div right?? Commented Apr 5, 2013 at 13:17
  • If you already have your form on the page as a hidden item, then reveal it with a click action, that may work out better for you. Commented Apr 5, 2013 at 13:18
  • ...also, if your external form requires its own JavaScript in order to function, make sure the scripts are already loaded on the parent page, or loaded onto the page with getScript(). Commented Apr 5, 2013 at 13:19
  • everything within the div "dialogbox" will be generated by a php page when you click the "opendialogbtn" id which calls "passtophp(...). Commented Apr 5, 2013 at 13:28

3 Answers 3

1

In the select dropdown you want to add an onclick call. You then want to make everything in the javascript a function that you call from the onclick. An updated JSbin is with the answer is here : http://jsbin.com/etuhur/13/edit

Sign up to request clarification or add additional context in comments.

Comments

0

delegate your change event with on

  $(document).on('change','select',function(){
   ....
  });

1 Comment

gave that a shot, but unfortunately no response from either dropdown.
0

Can you try to load your form functions after the dialog window opens

EDIT I have placed $(this).dialog('close'); above return false

$( "#dialogbox" ).dialog({

        autoOpen: false,
        modal: true,
        width: 'auto',
        show: {
            effect: "blind",
            duration: 1000
        },
        hide: {
            effect: "explode",
            duration: 1000
        },

        buttons: {
            //This function handles passing in the form data generated by getdialogbox.php 
            'Submit' : function(){
                $.ajax({
                    type: "POST",
                    url: "include/insertToDB.php",
                    data: $("#htmlform").serialize(),

                    success: function(){
                        $("#htmlform").submit();
                    }
                });
                $(this).dialog('close');
                return false;


            }
        },
        open: function( event, ui ) {    
            var $inputs = $('select.titans');
            var $controller = $('select.controller');
            $('select').change(function(){
                if($controller.val() !== ''){
                    $inputs.prop('disabled', $(this).val() !== '');
                    $inputs.val('');
               }else            {
                    $inputs.prop('disabled',false); 
               }
           });
        }

    });

3 Comments

yep, gave that a shot. Still doesn't seem to recognize the function.
there is an undefined function called passtophp() in your jsbin document which causes to malfunction of your code. is it defined in your original document?
passtophp() is defined, but not in the JSBin as I'm not sure how to recreate php pages in JSbin, but it basically creates a form similar to what is in the JSbin. I've tried the updated answer, but the dropdowns are still not disabling the other one. I appreciate your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.