編輯將醫療手術事件添加到Google日曆的表單。在表單上是一個(外科醫生列表)選擇框,它從index.php文件中提取選項值。我試圖改變這種情況,讓用戶通過在文本框中輸入名稱然後單擊「添加」按鈕來將「外科醫生」添加到該選擇框列表中。需要用戶能夠將「添加選項」添加到選擇列表中
我的解決方案是在「外科醫生列表」選擇框下添加一個文本字段和一個按鈕。在名稱中鍵入,然後單擊提交按鈕會將新的外科醫生姓名寫入XML文件。然後,我將「外科醫生列表」選擇框從XML文件中拉出它的選項值。
我能夠創建輸入框和按鈕,將新的外科醫生名稱添加到XML文件,但現在我有兩個提交按鈕。當我嘗試將新的外科醫生姓名添加到XML文件時,它認爲我已經完成了整個表單,並且正在嘗試提交它。如何在不提交表單的情況下將新選項值發送到XML文件?任何信息表示讚賞。
這是當前選擇框(不是從XML文件還拉)和我下面的XML添加現場...
<input type="hidden" name="action" value="<?php if($edit) echo 'edit';else echo 'insert';?>">
<input type="hidden" name="event_id" value="<?php if($edit) echo $event_data['id'];else echo '0';?>">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<label for="event_title">Surgeon Name <span class="required">*</span></label>
<select name="event_title" id="event_title" class="form-control required">
<option value="BERASI"> BERASI</option>
<option value="BERGHOFF"> BERGHOFF</option>
<option value="BIGGS"> BIGGS</option>
<option value="BORUS"> BORUS</option>
<option value="BURKE"> BURKE</option>
<option value="CANNONE"> CANNONE</option>
<option value="DEARBORN"> DEARBORN</option>
</select>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<form action="index.php" method="post">
<label for="surgeon" >Surgeon</label>
<input type="text" name="surgeon" class="btn btn-secondary"/>
<input type="submit" name="ok" value="add"/>
</div>
</div>
目前提交我的除了與衝突在窗體上按鈕在這裏...
<input type="hidden" name="action" value="<?php if($edit) echo 'edit';else echo 'insert';?>">
<input type="hidden" name="event_id" value="<?php if($edit) echo $event_data['id'];else echo '0';?>">
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<label for="event_title">Surgeon Name <span class="required">*</span></label>
<select name="event_title" id="event_title" class="form-control required">
<option value="BERASI"> BERASI</option>
<option value="BERGHOFF"> BERGHOFF</option>
<option value="BIGGS"> BIGGS</option>
<option value="BORUS"> BORUS</option>
<option value="BURKE"> BURKE</option>
<option value="CANNONE"> CANNONE</option>
<option value="DEARBORN"> DEARBORN</option>
</select>
</div>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="form-group">
<form action="index.php" method="post">
<label for="surgeon" >Surgeon</label>
<input type="text" name="surgeon" class="btn btn-secondary"/>
<input type="submit" name="ok" value="add"/>
</div>
</div>
這裏是我的窗體的圖像... enter image description here
這裏是搖擺JSC代碼...
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.net.URL;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.ComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class MemComboBoxDemo extends JFrame {
protected MemComboBox urlComboBox = new MemComboBox();
public MemComboBoxDemo() {
super();
setSize(300, 100);
getContentPane().setLayout(new BorderLayout());
JPanel p = new JPanel();
p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS));
p.add(new JLabel("Address"));
urlComboBox.load("addresses.dat");
ComboBoxListener lst = new ComboBoxListener();
urlComboBox.addActionListener(lst);
MemComboAgent agent = new MemComboAgent(urlComboBox);
p.add(urlComboBox);
getContentPane().add(p, BorderLayout.NORTH);
WindowListener wndCloser = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
urlComboBox.save("addresses.dat");
System.exit(0);
}
};
addWindowListener(wndCloser);
setVisible(true);
urlComboBox.grabFocus();
}
class ComboBoxListener implements ActionListener{
public void actionPerformed(ActionEvent evt) {
System.out.println(urlComboBox.getSelectedItem());
}
}
public static void main(String argv[]) {
new MemComboBoxDemo();
}
}
class MemComboAgent extends KeyAdapter {
protected JComboBox comboBox;
protected JTextField editor;
public MemComboAgent(JComboBox c) {
comboBox = c;
editor = (JTextField) c.getEditor().getEditorComponent();
editor.addKeyListener(this);
}
public void keyReleased(KeyEvent e) {
char ch = e.getKeyChar();
if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch))
return;
int pos = editor.getCaretPosition();
String str = editor.getText();
if (str.length() == 0)
return;
for (int k = 0; k < comboBox.getItemCount(); k++) {
String item = comboBox.getItemAt(k).toString();
if (item.startsWith(str)) {
editor.setText(item);
editor.setCaretPosition(item.length());
editor.moveCaretPosition(pos);
break;
}
}
}
}
class MemComboBox extends JComboBox {
public static final int MAX_MEM_LEN = 30;
public MemComboBox() {
super();
setEditable(true);
}
public void add(String item) {
removeItem(item);
insertItemAt(item, 0);
setSelectedItem(item);
if (getItemCount() > MAX_MEM_LEN)
removeItemAt(getItemCount() - 1);
}
public void load(String fName) {
try {
if (getItemCount() > 0)
removeAllItems();
File f = new File(fName);
if (!f.exists())
return;
FileInputStream fStream = new FileInputStream(f);
ObjectInput stream = new ObjectInputStream(fStream);
Object obj = stream.readObject();
if (obj instanceof ComboBoxModel)
setModel((ComboBoxModel) obj);
stream.close();
fStream.close();
} catch (Exception e) {
System.err.println("Serialization error: " + e.toString());
}
}
public void save(String fName) {
try {
FileOutputStream fStream = new FileOutputStream(fName);
ObjectOutput stream = new ObjectOutputStream(fStream);
stream.writeObject(getModel());
stream.flush();
stream.close();
fStream.close();
} catch (Exception e) {
System.err.println("Serialization error: " + e.toString());
}
}
}
最簡單的方法是如果用戶添加了一個新的外科醫生姓名,請將其作爲提交操作的一部分(從此將其添加到框中),而不是試圖在即時執行該操作。 –
你會碰到一個我能看到的例子嗎?任何信息apprecaited! –