简体   繁体   中英

how can i send value and text of dropdown to another page using POST/GET

Below code is one.php. i want to take text as will as value and to next page send_mail.php using POST/GET.

so how it can be done?

<form action="send_mail.php" name="choose_aff" method="POST">
<select name="company" id="company" class="company_select" style="width:250px;" onchange="submit()">
<option value="">Select</option>
<option value="123">abc</option>
<option value="354">xyz</option>
</select>
</form>

you can create hidden inputs

<input type="hidden" id="companyName" value="">
<input type="hidden" id="companyId" value="">

then on drop down change you can set these hidden inputs

$(function() {
    $("#company").change(function() {
        var companyName = $('#company:selected').text();
        var companyId = $('#company').val();
        $('#companyName').val(companyName);
        $('#companyId').val(companyId );
    });
});    

then when you submit your form you can get values like

$companyName = $_POST['companyName '];
$companyId = $_POST['companyId '];

You created the form in the first place. You already have the information needed to associate 123 with abc and 345 with xyz.

Include that information in the program which is processing the form (you could hard code it as an associative array or store it in a database).

Then just look it up:

$number = $_POST['company'];
$letters = $my_map[$number];
<form action="test1.php" name="choose_aff" method="POST">
    <select name="company" id="company" class="company_select" style="width:250px;" onchange=" document.getElementById('text_content').value=this.options[this.selectedIndex].text">
    <option value="">Select</option>
    <option value="123">abc</option>
    <option value="354">xyz</option>
    </select>

    <input type="hidden" name="test_text" id="text_content" value="" />
    <input type="submit" name="submit" value="submit">
</form>

PHP Code

echo $_POST['company'];
echo $_POST['test_text'];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM