
how to get content of alert message into textfield using javascript

Getting content of alert message into text field
1)If you want the code in java, then here is it:
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class Validation{
public static void main(String[] args){
JFrame f=new JFrame();
f.setLayout(null);
final JRadioButton radio=new JRadioButton("Select");
final JCheckBox check=new JCheckBox("Check");
final JTextField text=new JTextField(20);
JButton b=new JButton("Check");
b.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
if(radio.isSelected()&&!check.isSelected()){
String st="You have selected radiobutton instead of checkbox";
JOptionPane.showMessageDialog(new JFrame(), st, "Dialog",JOptionPane.ERROR_MESSAGE);
text.setText(st);
}
else{
text.setText("");
}
}
});
radio.setBounds(10,10,100,20);
check.setBounds(10,40,100,20);
b.setBounds(10,70,100,20);
text.setBounds(10,110,200,20);
f.add(radio);
f.add(check);
f.add(b);
f.add(text);
f.setVisible(true);
f.setSize(300,200);
}
}
2)If you want the code in html-javascript, then here is it:
<html>
<script>
function check(){
var ch=document.getElementById('check');
var r=document.getElementById('radio');
if(r.checked&&!ch.checked){
var st="You have selected radiobutton instead of checkbox";
alert(st);
document.getElementById("text").value=st;
}
else{
document.getElementById("text").value="";
}
}
</script>
Select<input type="radio" id="radio"><br>
Check<input type="checkbox" id="check"><br>
<input type="button" value="check" onclick="check();"><br>
<input type="text" id="text">
</html>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.