tags:

views:

125

answers:

2

Hi, I have 2 text boxes and a submit button.On clicking on the submit button the value from the first textbox should get populated in the second textbox.Can you help me with this. Thankyou in advance.

+1  A: 
JTextField txtFld1 = new JTextField(10); // 10 columns
JTextField txtFld2 = new JTextField(10);
JButton btn = new JButton("Submit");

// Register action listener responsible for copying text
// from txtFld2 to txtFld1.
btn.addActionListener(new ActionListener() {
  public void actionPerformed(ActionEvent evt) {
    txtFld1.setTxt(txtFld2.getText());
  }
});
Adamski
can you tell me something in javascript
jacinta
Sorry - I don't know Javascript!
Adamski
+2  A: 
<input type="submit" onclick="triggerSubmit();" value="Submit" />

<script type="text/javascript">
  function trigerSubmit(e){
    var textbox1 = document.getElementById('textbox1');  
    var textbox2 = document.getElementById('textbox2');  

    textbox2.value = textbox1.value;
    textbox1.value = '';

    return false; // Prevent form auto submittal

  }
</script>
Ballsacian1
You can directly `return false;` in `trigerSubmit`.
KennyTM