Populate value from one textbox to another on clicking on submit button
I have 2 text boxes and a submit button.On clicking on the submit button the value from the fi开发者_JAVA百科rst textbox should get populated in the second textbox.Can you help me with this. Thankyou in advance.
<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>
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());
}
});
精彩评论