Come risposta @Shoaib, non è necessario alcun jQuery o Javascript. Puoi farlo semplicemente con puro html!
<form method="POST" action="index.php?action=contact_agent">
<select name="agent_id" required>
<option value="1">Agent Homer</option>
<option value="2">Agent Lenny</option>
<option value="3">Agent Carl</option>
</select>
<input type="submit" value="Submit">
</form>
- Rimuovere
&agent_id=
dall'azione forma dal momento che non ne hai bisogno c'è.
- Aggiungi
name="agent_id"
al select
- Opzionalmente add parola
required
non indicano che è necessaria questa selezione.
Dal momento che si sta utilizzando PHP, poi inviando il modulo per index.php
si può prendere agent_id
con $_POST
/** Since you reference action on `form action` then value of $_GET['action'] will be contact_agent */
$action = $_GET['action'];
/** Value of $_POST['agent_id'] will be selected option value */
$agent_id = $_POST['agent_id'];
A conclusione per un compito così semplice non si dovrebbe usare qualsiasi javascript o jQuery. Per @FelipeAlvarez che risponde tuo commento
fonte
2015-11-24 13:44:18
yuck. Qualche ragione per cui non puoi semplicemente usare un post invece di un get? – JohnFx
È possibile farlo solo tramite HTML? –
@JohnFx - Presumo che 'yuck' sia per' mixare sia POST che GET nella stessa query' che, sebbene strana, è consentita dalle specifiche HTML. Vedere la risposta di @Marko per un esempio del server che prevede questo comportamento. –