Asked  7 Months ago    Answers:  5   Viewed   38 times
<select id="animal" name="animal">                      
<option value="0">--Select Animal--</option>
<option value="1">Cat</option>
<option value="2">Dog</option>
<option value="3">Cow</option>


I have a dropdown like this. What I want, I want to get selected value and text in button submit using PHP. I mean if it's selected 1st one. I want to get both 1 and Cat

Please help. thank you.


$animals = array('--Select Animal--', 'Cat', 'Dog', 'Cow');
$selected_key = $_POST['animal'];
$selected_val = $animals[$_POST['animal']];

Use your $animals list to generate your dropdown list; you now can get the key & the value of that key.

Wednesday, March 31, 2021
answered 7 Months ago

In testing2.php use the following code to get the name:

if ( ! empty($_POST['name'])){
    $name = $_POST['name']);

When you create the next page, use the value of $name to prefill the form field:

Name: <input type="text" name="name" id="name" value="<?php echo $name; ?>"><br/>

However, before doing that, be sure to use regular expressions to verify that the $name only contains valid characters, such as:

$pattern =  '/^[0-9A-Za-zÁ-Úá-úàÀÜü]+$/';//integers & letters
if (preg_match($pattern, $name) == 1){
} else {
    //reload form with error message
Wednesday, March 31, 2021
answered 7 Months ago

Try to execute below code. Please select CD Price:

<select name="CDPrice">
    <option value="">
        include 'database_conn.php';
        if (!( is_object($conn) && ( get_class($conn) == 'mysqli' ))) {
            die("DB connection failure.");
        $rsCDprice = mysqli_query($conn, "SELECT DISTINCT nmc_cd.CDPrice FROM nmc_cd");
        if (!$rsCDprice) {
            die("No result from DB query."); //probably invalid SQL, table error, etc.
        if ($rsCDprice->num_rows < 1) {
            die("No rows returned from DB query."); //query runs OK, but nothing is found in DB to match.
        while ($Catpriceresult = mysqli_fetch_array($rsCDprice)) {
            echo "<option value='" . $Catpriceresult[0] . "'>" . $Catpriceresult[0] . "</option>";
Saturday, May 29, 2021
answered 5 Months ago

First, td elements don't have a value attribute, so calling .value on them won't do a thing. Second, the value is actually on the input element, so you need to do mytable.getElementsByTagName('input') instead. Even better would be to give your input fields ids and then use getElementById. This would mean you could alter your HTML without your JS breaking.

Monday, August 30, 2021
answered 2 Months ago

Check xmlns namspace.

the following code i wrote to emulate your problem works fine:

<?xml version="1.0" encoding="utf-8"?>

        import mx.collections.XMLListCollection;
        import mx.messaging.messages.SOAPMessage;
        var _result:*;

        protected function  
            var xml:XML = <Body>

        _result = new XMLListCollection(new XMLList(xml.myusersResponse.myusersReturn));




<s:FormItem label="Label">
    <s:DropDownList id="dropDownList"
        <s:AsyncListView list="{_result}"/>

But if you add xmlns=" to myusersResponse tag it fails.

EDIT: In case you need namespace workaround, I just answered Jack Moores question with namespace solution here My flex code does not parse the soap response properly

Saturday, October 23, 2021
answered 2 Days ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :