L
L
Lavrov952018-03-26 13:00:26
PHP
Lavrov95, 2018-03-26 13:00:26

How to get text in select option?

How to get text in select option?

<form method = "post">
    <div class="form-group">
        <label for="countryName">Company type</label>
        <select class="form-control" id="countryName" name="countryName">
            <option value="1">Russia</option>
            <option value="2">United States</option>
            <option value="3">United Kingdom</option>
        </select>
    </div>
    <button type="submit" name="companyRegister" class="btn btn-default">Register </button>
</form>

<?php
if(isset($_POST['companyRegister'])){
    $countryName = $_POST['countryName'];
    echo $countryName;
}
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Epifanov, 2018-03-26
@kacheleff

take it via JS before sending the submit and put it in a hidden field

B
Boris Korobkov, 2018-03-26
@BorisKorobkov

First, it is more correct to name not countryName, but countryId.
Secondly, your backend needs to know the id and name matches anyway. Additionally, this information does not need to be transmitted from the front.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question