0

In my MVC application have included a button called form Field. whenever user clicks on that button dropdownlist gets displayed in modal box that contains text, checkbox etc as option. code for form field and drop downlist:

<input type="button" id="FormField" name="Form Field" value="Form Field" style="width: 110px; height: 30px; background-color: #FFFFFF;"  onclick="return FormField_onclick()" />


function FormField_onclick(box) {
             dhtmlx.modalbox({
                 title: "Form Field Creation Tool",
                 text: "<div id='form_in_box'><div ><label>Type: <select id='Type' name='Type'><option>Text</option><option>Checkbox</option><option>Radio</option><option>DropDown</option><option>Listbox</option></select></label><br></div><div><span class='dhtmlx_button'><input type='submit' value='Select' style='width: 86px' onclick='Select_type(this)'></span><span class='dhtmlx_button'><input type='button' value='Cancel' onclick='close_file(this)' style='width:80px;'></span></label></div></div>",
                 width: "300px"
             });  
         }

Whenever user selects particular option from dropdownlist for example if user selects text option and clicks Select button than textbox should get inserted at cursor position. code for select button:

 function Select_type(box) {
             var tp = document.getElementById('Type');

             switch (tp) {
                 case "text":
                     {
                     var editor = CKEDITOR.instances.message;
                        editor.insertHtml('<input type="text" id="tx" name="tx" style="width: 110px; height: 30px" />'); 
                 }
                     break;
                 case "Checkbox": { var editor = CKEDITOR.instances.message;
                                        editor.insertHtml('<input type="checkbox" id="chk" name="chk" value="Checkbox" style="width: 110px; height: 30px" />');} 
                     break;
                 case "Radio": 
                     { 
                 var editor = CKEDITOR.instances.message;
                 editor.insertHtml('<input "radio" id="rd" name="rd" value="radio" style="width: 110px; height: 30px" />');
}
                     break;
                 case "DropDown": alert("DropDown");
                     break;
                 case "Listbox": alert("Listbox");
                     break;
             }              
             dhtmlx.modalbox.hide(box);
         }

but this doesn't work for me. Even the alert doesn't work. And also don't know how can i include dropdown and list in it

2 Answers 2

1

You want to do the switch on:

document.getElementById('Type').value

and not on the element it self, as it doesn't equals none of the cases you provided.

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

5 Comments

ok... It works .. Can you please tell me how can i include drop down and list in my application. Similarly the present code that am using for checkbox doesn't gets checked when I click on it. An empty checkbox without a check mark gets displayed
you can include a dropdown using the <select><option>Option1</option><option>Option2</option></select>, and Lists using <ul><li> some item</li><li>some other item</li></ul>. you can read here: w3.org/TR/html401/struct/lists.html about ordered list (<ol>) and unordered list (<ul>) and lists in general.
but I want user to include option. I mean empty drop dwon list and the user will include the option in it based upon his/her needs
is this what you mean? jsfiddle.net/r89bC any way, create a new question for other questions you have.
Please check this site pdfescape.com/open in this site under create new pdf there is a option called form field ..i want similar thing
0

You could use an object literal for the switch statement if you wanted to...

var sw = {
    hello: function () {
        console.log("hello");
    },
    goodbye: function () {
        console.log("goodbye");
    }
}
var str = "hello";
sw[str](); //logs hello

Heres an explanation: http://www.dyn-web.com/tutorials/obj_lit.php

I think you need to clarify your question though and tag it appropriately...

Comments

Your Answer

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