• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to populate a value in text box

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
Thorugh jsp, a page displayed with some fields like radio button, textbox (names A), textbox1 ( named B)etc. Here textbox A have some value. This is done through one jsp(say X)when I click the radio button, the textbox A value is selected and some logic will be performed and in same page again one other form will be displayed.
The second form contains again a radio button, textbox value etc. This is something like anotehr jsp(say Y)

My requirement is when I click the radio button in second form data of same page, the corrosponding textbox value shoudl go to the first form textbox1 (named B) place.
Now both X and Y are in same page.This has to be done using javascript only

How to do this in javascript.Please do the need ful.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure there is multiple jsp is getting dynamically include to your one jsp file.
please check the code may be there is multiple <div> will be there . where while click on checkbox
it will make the <div> visiable...

If this is the case , if you are using multiple <div> and making it enable by clicking on check box then you can do it by javascript.


If this is not the scenario and you are calling the multiple jsp by <jsp:include> on click on checkbox... then javascript will not
help. You have to take a bean class and has to set the value in the jspbean and populate that bean value to the first jsp..

as when it will call first time there is no value in the bean,... when you click the second jsp you have to set the text value to the jspbean and has to call the same page....

while doing this ... the textfield in the first page will get the value from the jspbean .

Please note that keep the scope of the jspbean as session.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know how to set a textbox value with JavaScript? Have you worked with the onchange event before?

Eric
 
Baji Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

binayakumar patel wrote:Are you sure there is multiple jsp is getting dynamically include to your one jsp file.
please check the code may be there is multiple <div> will be there . where while click on checkbox
it will make the <div> visiable...

If this is the case , if you are using multiple <div> and making it enable by clicking on check box then you can do it by javascript.


If this is not the scenario and you are calling the multiple jsp by <jsp:include> on click on checkbox... then javascript will not
help. You have to take a bean class and has to set the value in the jspbean and populate that bean value to the first jsp..

as when it will call first time there is no value in the bean,... when you click the second jsp you have to set the text value to the jspbean and has to call the same page....

while doing this ... the textfield in the first page will get the value from the jspbean .

Please note that keep the scope of the jspbean as session.



Thank you for your inputs. Yes there is <div> in the forms. So it must be done through javascript.
Please do the needful.
 
Baji Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:Do you know how to set a textbox value with JavaScript? Have you worked with the onchange event before?

Eric



Yes Eric. I am not extremely worked with JS.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so add an onchange event



It would be better to do it in an unobtrusive manner, but that is the basic idea.

Eric
 
Baji Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Eric Pascarello wrote:so add an onchange event



It would be better to do it in an unobtrusive manner, but that is the basic idea.

Eric



Thank you. Let me try and update you.
 
Baji Roy
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Baji Roy wrote:

binayakumar patel wrote:Are you sure there is multiple jsp is getting dynamically include to your one jsp file.
please check the code may be there is multiple <div> will be there . where while click on checkbox
it will make the <div> visiable...

If this is the case , if you are using multiple <div> and making it enable by clicking on check box then you can do it by javascript.


If this is not the scenario and you are calling the multiple jsp by <jsp:include> on click on checkbox... then javascript will not
help. You have to take a bean class and has to set the value in the jspbean and populate that bean value to the first jsp..

as when it will call first time there is no value in the bean,... when you click the second jsp you have to set the text value to the jspbean and has to call the same page....

while doing this ... the textfield in the first page will get the value from the jspbean .



Please note that keep the scope of the jspbean as session.



Thank you for your inputs. Yes there is <div> in the forms. So it must be done through javascript.
Please do the needful.



Hi Patel,

I have done as below. But Its not populating the vaule in textbox.

In Y.jsp the code is like this.

var f1 = top.document.forms['tform'];
var f2 = top.document.forms['tform1'];

<input type=radio name=data value="data_res" onclick="javascript:getData();/>

on getData() method I have written the below code.

function getData() {

var rd = document.getElementsByName('data');

for(var i = 0; i < rd.length; i++) {
if(rd[i].checked) {
field = parent.document.createElement('INPUT');
field.value = rd[i].value;
document.forms[tform].data_back.value = rd[i].value; // Here data_back is the name of the textbox for form name tform which is the upper form already displayed
(X.jsp)

}
}
f2.submit();
}

The above code is not replacing the selected the text value into the upper form textbox location. Please let me know whether I am missing something.

Baji Roy.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
WHy are you creating form elements? I thought you had form elements on the page you were changing the value of? Why are you not adding the elements you created to the page? They are not attached to the form.

Eric
 
binayakumar patel
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Hi Patel,

I have done as below. But Its not populating the vaule in textbox.

In Y.jsp the code is like this.

var f1 = top.document.forms['tform'];
var f2 = top.document.forms['tform1'];

<input type=radio name=data value="data_res" onclick="javascript:getData();/>

on getData() method I have written the below code.

function getData() {

var rd = document.getElementsByName('data');

for(var i = 0; i < rd.length; i++) {
if(rd[i].checked) {
field = parent.document.createElement('INPUT');
field.value = rd[i].value;
document.forms[tform].data_back.value = rd[i].value; // Here data_back is the name of the textbox for form name tform which is the upper form already displayed
(X.jsp)

}
}
f2.submit();
}

The above code is not replacing the selected the text value into the upper form textbox location. Please let me know whether I am missing something.

Baji Roy.



I know you have not given the complete code but still concentrate these lines:
var rd = document.getElementsByName('data');
is the data is a TextBox or RadioButton

that you are checking this with an array
rd[i].checked

I am not able to understand here .... Because you are taking the rd value to store in the "data_back"
If it is a checkBox or RadioButton we can check for "checked" or "Unchecked", if it is a TextBox then how you are checking for "checked"

You are creating a new filed and storing the data to it.... But I have not seen any line where you are using "f2" to get data from the textbox of second form.

you are using rd[i].value ... if it is a checkBox or RadioButton then it will return you only true and false.
So no where I found that you are taking the data from the form2 -> textbox

I think this code may help you , Please modify this as per your requirement:
 
How do they get the deer to cross at the signs? Or to read this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic