Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clarification in Jsp
09-05-2008, 09:22 PM
Post: #1
Clarification in Jsp
I have a jsp file say a.jsp . When i click on a button on this jsp file it pops up another jsp say b.jsp which has a textbox and a save button. Now when i enter some details in the text box and click on save , i want the info from the text box in b.jsp to be passed on to a.jsp and then the form in a.jsp needs to be submitted for further action. Kindly let me know how this can be done if possible with an example.
Find all posts by this user
Quote this message in a reply
09-05-2008, 09:47 PM
Post: #2
RE: Clarification in Jsp
There is a simple JavaScript way to do this job. Basically you want to pass the value from your pop up window to the parent. So try the following code.

a.jsp
Code:
<html>
    <body>
        <form name="frmTest">
            <input type="text" name="txtPopupData">

            <input type="button" value="Open pop up" onclick="window.open('b.jsp')" />
        </form>
    </body>
</html>

b.jsp
Code:
<html>
    <head>
        <script language="javascript">
            function saveData(){
                // pass the value from the pop up window to parent window.
                window.opener.document.frmTest.txtPopupData.value = document.abc.txtData.value;
                

                // Perform whatever you want like submitting the form ...

                // Just close this window if needed.
                window.close();
            }
        </script>
    </head>
    <body>
        <form action="" name="abc">
            <input type="text" name="txtData">
            <input type="button" name="btn" value="Save" onclick="saveData()" />
        </form>
    </body>
</html>

Here you are passing the value entered in the pop up window to a form element in parent window.

I think the above code solve your problem.
Visit this user's website Find all posts by this user
Quote this message in a reply
09-08-2008, 04:47 PM
Post: #3
RE: Clarification in Jsp
albinjoseph Wrote:There is a simple JavaScript way to do this job. Basically you want to pass the value from your pop up window to the parent. So try the following code.

a.jsp
Code:
<html>
    <body>
        <form name="frmTest">
            <input type="text" name="txtPopupData">

            <input type="button" value="Open pop up" onclick="window.open('b.jsp')" />
        </form>
    </body>
</html>

b.jsp
Code:
<html>
    <head>
        <script language="javascript">
            function saveData(){
                // pass the value from the pop up window to parent window.
                window.opener.document.frmTest.txtPopupData.value = document.abc.txtData.value;
                

                // Perform whatever you want like submitting the form ...

                // Just close this window if needed.
                window.close();
            }
        </script>
    </head>
    <body>
        <form action="" name="abc">
            <input type="text" name="txtData">
            <input type="button" name="btn" value="Save" onclick="saveData()" />
        </form>
    </body>
</html>

Here you are passing the value entered in the pop up window to a form element in parent window.

I think the above code solve your problem.

Thanks a lot Albin. I ll try it out and get back if i have any more queries.
Find all posts by this user
Quote this message in a reply
09-09-2008, 04:34 PM
Post: #4
RE: Clarification in Jsp
albinjoseph Wrote:There is a simple JavaScript way to do this job. Basically you want to pass the value from your pop up window to the parent. So try the following code.

a.jsp
Code:
<html>
    <body>
        <form name="frmTest">
            <input type="text" name="txtPopupData">

            <input type="button" value="Open pop up" onclick="window.open('b.jsp')" />
        </form>
    </body>
</html>

b.jsp
Code:
<html>



    <head>
        <script language="javascript">
            function saveData(){
                // pass the value from the pop up window to parent window.
                window.opener.document.frmTest.txtPopupData.value = document.abc.txtData.value;
                

                // Perform whatever you want like submitting the form ...

                // Just close this window if needed.
                window.close();
            }
        </script>
    </head>
    <body>
        <form action="" name="abc">
            <input type="text" name="txtData">
            <input type="button" name="btn" value="Save" onclick="saveData()" />
        </form>
    </body>
</html>

Here you are passing the value entered in the pop up window to a form element in parent window.

I think the above code solve your problem.

Hi Albin, I tried this one out..but still I have problems. This is what I did.

A.jsp

i hava a generate file button in this jsp and onclick of this button i get the pop up which is B.jsp. I create a hidden input field in A.jsp and in B.jsp I enter some text and click on a save button. On saving this value should be passed to the hidden field in A.jsp and A.jsp needs to be submitted.

Here actually when i enter a value in B.jsp and click on save the form A.jsp is getting submitted but the value of the hidden field still remains null.. when i try to retrieve it from backend using a bean and when i try to display in on the console using logger.info it shows a null value. Kindly help.


Or is it posible to submit A.jsp in B.jsp. Like,

B.jsp

<html>
<head>
<script language="javascript">
function saveData(){
// pass the value from the pop up window to parent window.
window.opener.document.frmTest.txtPopupData.value = document.abc.txtData.value;


//Here can I give

window.opener.document.frmTest.actionType.value="some action type";
window.opener.document.frmTest.action.value="some action.htm";
window.opener.document.frmTest.submit();
//is this possible?


is this possible?

// Perform whatever you want like submitting the form ...

// Just close this window if needed.
window.close();
}
</script>
</head>
<body>
<form action="" name="abc">
<input type="text" name="txtData">
<input type="button" name="btn" value="Save" onclick="saveData()" />
</form>
</body>
</html>
Find all posts by this user
Quote this message in a reply
09-09-2008, 08:59 PM
Post: #5
RE: Clarification in Jsp
Try the following code.

a.jsp
PHP Code:
<html>
    <
body>
        
        <
form name="frmTest" action="blabla">
            <
input type="hidden" name="txtPopupData">

            <
input type="button" value="Open pop up" onclick="window.open('b.jsp')" />
        </
form>
    </
body>
</
html

b.jsp
PHP Code:
<html>



    <
head>
        <
script language="javascript">
            function 
saveData(){
                
// pass the value from the pop up window to parent window.
                
window.opener.document.frmTest.txtPopupData.value document.abc.txtData.value;
                
window.opener.document.frmTest.action "ABServlet";
                
window.opener.document.frmTest.method "POST";    
                
window.opener.document.frmTest.submit();
            }
        
</script>
    </head>
    <body>
        <form action="" name="abc">
            <input type="text" name="txtData">
            <input type="button" name="btn" value="Save" onclick="saveData()" />
        </form>
    </body>
</html> 

This code works perfectly for me.
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: