Member Avatar for feoperro

Hi,

I'm trying to use the request.getParameter("myInputField") on Page A. The problem is that the input field "myInputField" is on Page B. Does anyone know of a way to retrieve from Page A, the value of the input field that is on Page B?

Thanks,
-Ash

Hi,

I'm trying to use the request.getParameter("myInputField") on Page A. The problem is that the input field "myInputField" is on Page B. Does anyone know of a way to retrieve from Page A, the value of the input field that is on Page B?

Thanks,
-Ash

You need to submit the form that is at Page B to the Page A.
In details:
>The input field must be inside a form tag
>When you submit, the control will be transferred to the page that you define at the action attribute of the form tag
> At the next page you will have access to everything the form tag contained:

<form action="pageB.jsp">

<input type="text" name="myInputField" />
<input type="submit" value="Click here to submit" />

</form>

pageB.jsp:

<%
String myInputField = request.gteParameter("myInputField");
%>
Member Avatar for feoperro

Say for example, the submit does not change Page A to Page B, but makes a popup of Page B instead? While Page A remains active in the background. Bare in mind that Page A will still use a form "post" once the button that brings up the pop up is clicked.

Post code of the page that opens the pop-up

Member Avatar for feoperro

Page A:
(This is the page that holds the input area's and submit button)

<script type='text/javascript'>
function startPopUp() {
document.PageAForm.submit();
window.open("searchRequestPopUp?searchId=" +  request.getParameter('searchPhrase') + ",'window','width=800,height=300','scrollbars=yes','resizable=yes','statusbar=yes','menubar=yes','toolbar=yes','dependent=yes');
}
</script>

<input type='submit' value='Search' name='sourceListSearch' onclick='startPopUp()'/>

Page B:
(This is the pop up window that I want to have the ability to reference the input area's from Page A)

out.println(""+request.getParameter("searchId"));

This DOES work, the problem, however, is that the first time Page B (the pop up) is loaded, the value is null; and if you submit Page A again, then Page B recognises the first input that was submitted on Page A instead of the second one.
For example: If I typed in "2" on Page A and sent it across to Page B, then Page B would display "null". If I typed "3" on Page A and clicked submit again then Page B will display "2" (The first value that was entered).
So in other words, Page B (The Pop Up) is always one step behind.

Thanks again,
-Ash

Member Avatar for feoperro

I've also tried hardcoding the number "2" into the input area on Page A that I want to reference on Page B. The first time the pop up runs, the output printed is still "null".

The first time the page loads this is null:

request.getParameter('searchPhrase')

So this is translated to:

window.open("searchRequestPopUp?searchId=null", . . .

So when the pop up opens the searchId has value "null".

But after you submit the form of page A you send at the request the "searchPhrase" so this has value:

window.open("searchRequestPopUp?searchId=valueEntered", . . .

And you get it at the pop up.

I would suggest to remove this line:

function startPopUp() {
// REMOVE //document.PageAForm.submit();
window.open("searchRequestPopUp?searchId=" +  request.getParameter('searchPhrase') + ",'window','width=800,height=300','scrollbars=yes','resizable=yes','statusbar=yes','menubar=yes','toolbar=yes','dependent=yes');
}

You don't need it. All you need is to open the new page with what you entered at the search text. Right? Then you can do this:

<script type='text/javascript'>
function startPopUp() {

var v = document.getElementById("searchPhraseId").value;

window.open("searchRequestPopUp.jsp?searchId=" +  v, 'window','width=800,height=300','scrollbars=yes','resizable=yes','statusbar=yes','menubar=yes','toolbar=yes','dependent=yes');

}
</script>

<input type="text" name="search" id="searchPhraseId">

<input type='button' value='Search' name='sourceListSearch' onclick='startPopUp()'/>
Member Avatar for feoperro

Ya that worked :) Thanks you so much! 100%

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.