Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Get values from modal window

    I'm trying to get the value that was entered in a textarea in a modal window to place it in on a form.

    Situation is as follows:
    We have a jsp page with a number of textBoxes on them. The textboxes are non smartclient, but struts html:text boxes.
    Next to each textbox there is an icon. When clicking on the icon a popup should appear with a textarea in it and an "Ok" and "Cancel" button.
    When clicking on the "Ok" button the value that was entered in the textarea should be placed in the textbox on the form.
    Showing the popup works fine, but how can I get the value from the textarea in the modal window and place it on the form?
    And clear the value from the textArea afterwards?

    Some code snippets:

    The text boxes on the form with the image:
    Code:
    <html:text name="advancedTechSpecOverviewForm" property="value[${currentNode.id}]"/>
    <html:img src="/a2p/images/edit.png" onclick="showPopup();" altKey="techSpecManagement.button.edit" border="0" align="absbottom"></html:img>
    When clicking on the image the following function is executed:
    Code:
    function showPopup(){
        modalWindow.show();
    }
    In this function I would also set a hidden value on the form so I know which icon was clicked. So I can place the value from the textarea in the correct text box afterwards.

    This is the modalWindow:
    Code:
        isc.Window.create({
            ID: "modalWindow",
            title: "Enter value",
            autoSize:true,
            autoCenter: true,
            isModal: true,
            showModalMask: true,
            autoDraw: false,
            items: [
                isc.DynamicForm.create({
                    autoDraw: false,
                    height: 48,
                    width: 350,
                    padding:4,
                    name: "popup",
    					
                    fields: [
    					{	name: "value", 
    					    type: "textArea",
    					    width: "300",
    					    align: "left"
    					},
    					{type: "button", title: "Ok",
    		                 click: "closePopup(this);"
    		            },
    		            {type: "button", title: "Cancel",
    		                 click: "closePopup(this);"
    		            },
                    ]
                })
            ]
        });
    And this is the closePopup function:
    Code:
    function closePopup(obj){
       if(obj.title == "Ok"){
            alert("ok");
        }else if(obj.title == "Cancel"){
            alert("cancel");
        }
        modalWindow.hide();
    }
    In this function I would like to get the value from that modal window, place it in the correct textbox on the form and clear the textarea.
    But how can I get the value from that textArea and clear it afterwards?

    #2
    Never mind, I found a sollution :)
    After clicking on the "ok" or "cancel" button in the popup I execute another javascript function.
    As parameters I give the button that was clicked, and the form to which the button belongs to.
    Code:
    {type: "button", title: "Ok",
    	click: "closePopup(this.form, this);"
    }
    And the javascript function is as follows then:
    Code:
    	/*
    	 *	This function will perform the needed actions after the popup is closed.
    	 * 	If the user clicks on the "Cancel" button, nothing should happen.
    	 *	If the user clicks on the "Ok" button then the value from the textarea should be placed in the textBox next to the icon that the user clicked on.
    	 */
    	function closePopup(form, clickedButton){
    	    //Get the value from the textArea in the popup
    	    var enteredValue = form.getItem("Value").getValue() ;
    	    
    	    if(clickedButton.title == "Ok"){
    		    //User clicked "ok"
    		    //Get the textBox in which the text should be placed
    		    var nodeId = document.getElementById("nodeId").value;
    		    var textBox = document.getElementById("value" + nodeId);
    		    //Set the value
    		    textBox.value = enteredValue;
    	    }else if(clickedButton.title == "Cancel"){
    	        //User clicked "Cancel", nothing hould happen if its cancel
    	    }
    	    
    	    //Hide the window
    	    modalWindow.hide();
    	}
    I discoverd 1 problem though.
    Before the popup is shown the document.forms.length return 1.
    After the popup is closed it always returned 2.
    So now I always submit the last form in my document.

    Comment

    Working...
    X