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>
</select>

if($_POST['submit'])
{
$animal=$_POST['animal'];
}

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.

 Answers

27
$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
 
Zigglzworth
answered 7 Months ago
30

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){
    //continue
} else {
    //reload form with error message
}
Wednesday, March 31, 2021
 
Ultimater
answered 7 Months ago
36

Try to execute below code. Please select CD Price:

<select name="CDPrice">
    <option value="">
        <?php
        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>";
        }
        ?>
</select>
Saturday, May 29, 2021
 
williamcarswell
answered 5 Months ago
74

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
 
phirschybar
answered 2 Months ago
72

Check xmlns namspace.

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

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

    <![CDATA[
        import mx.collections.XMLListCollection;
        import mx.events.FlexEvent;
        import mx.messaging.messages.SOAPMessage;
        [Bindable]
        var _result:*;

        protected function  
            dropDownList_creationCompleteHandler(event:FlexEvent):void
        {
            var xml:XML = <Body>
                            <myusersResponse>
                              <myusersReturn>
                                <name>Nicole</name>
                                <age>50</age>
                              </myusersReturn>
                              <myusersReturn>
                                <name>Jayne</name>
                                <age>40</age>
                              </myusersReturn>
                               <myusersReturn>
                                <name>Alex</name>
                                <age>33</age>
                              </myusersReturn>
                            </myusersResponse>
                          </Body>;

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

    ]]> 
</fx:Script>

<fx:Declarations>

</fx:Declarations>

<s:FormItem label="Label">
    <s:DropDownList id="dropDownList"
                    creationComplete="dropDownList_creationCompleteHandler(event)"
                    labelField="name">
        <s:AsyncListView list="{_result}"/>
    </s:DropDownList>
</s:FormItem>

But if you add xmlns="http://Services.com 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
 
joe
answered 2 Days ago
joe
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 :