0
<select>
    <option value="1">one</option>
</select>

now i want to get 1 and "one" both using php..so plz reply me

5
Contributors
12
Replies
27
Views
5 Years
Discussion Span
Last Post by rahul_29
Featured Replies
  • 2

    Have an array with indexes the values and elements the words you want to represent the values: $numbers_array = array('1' => 'one', '2' => 'two', '3' => 'three'); // wrap everything within form tags echo '<form action="#" method="post">'; // use PHP to construct the select element echo '<select name="numbers">'; foreach($numbers_array … Read More

0

the value in the select option is 1, if you want to get a different value you can do so programmatically, or by changing the value in the field. changing the value is an obvious method so I won't show it.
giving the select a name so it is accessible
programmatically

<?php if($_POST['name']=="1") {
echo "1 one";
//or
$variable="1 one";
//or
$name="1";
$name2=="one";}
?>

Edited by almostbob

2

Have an array with indexes the values and elements the words you want to represent the values:

$numbers_array = array('1' => 'one', '2' => 'two', '3' => 'three');
// wrap everything within form tags
echo '<form action="#" method="post">';

// use PHP to construct the select element
echo '<select name="numbers">';
foreach($numbers_array as $value => $text) {
    echo " <option value='$value'>$text</option>"
}
echo "</select>";
// submit button
echo "<input name="submit" value="Submit" />";
echo "</form>";

// check if submit button was pressed
if(isset($_POST['submit'])) {
    $chosen_value = $_POST['numbers'];
    // display chosen value and text
    echo $chosen_value . ' - ' . $numbers_array[$chosen_value];
}

Edited by broj1: typos, what else

Votes + Comments
thanks..plz solve this also
0
Hi..broj1

now i have dropdown list like this



    <?php 
        for($i=0; $i<$count; $i++)
        {
            echo "<option value='".$countryName[$i][0]."'>".$countryName[$i][1]."</option>";  
        }
    ?>

    Here,$countryName[$i][0] is countryID and $countryName[$i][1] is countryName so now as per ur answer how i can store values in array..?? plz reply me now
0

The values are already in an array $countryName so just use them.

Maybe you post the whole code so I can get the picture.

0
<html>
    <body>
        <?php
            include("includes/connectionPool.php");
            $obj=new connectionPool;

            $getQuery="select * from country";
            $countryName=$obj->select($getQuery);
            $count=count($countryName);

    ?>

            <h3>Registration Form</h3>
            <h5>* fields are mandatory</h5>
            <form name="form1" id="myform" action="addDetails.php" method="post" enctype="multipart/form-data" 
             onsubmit="return requiredValidation()">

            <!-- <input type="hidden" name="verificationCode" value="" />-->
            <table>
            <tr>
                <td>First Name:*</td><td><input type="text" name="txtFirstName" value=""/></td>
            </tr>
            <tr>
                <td>Last Name:*</td><td><input type="text" name="txtLastName" value=""/></td>
            </tr>
            <tr>
                <td>Address:*</td><td><textarea cols="15" rows="5" name="txtAddress"></textarea></td>
            </tr>
            <tr>
                <td>Country:*</td><td><select id="txtCountry" name="txtCountry" onchange="getState(this.value)">

                                            <option value="">Select Country</option>
                                            <?php 
                                            for($i=0; $i<$count; $i++)
                                            {
                                                echo "<option value='".$countryName[$i][0]."'>".$countryName[$i][1]."</option>";  
                                            }
                                            ?>
                                      </select></td>
            </tr>
            <tr>
                <td>State:*</td><td><div id="statediv"><select id="txtState" name="txtState">
                                            <option value="">Select Country First</option>
                                                    </select></div></td>
            </tr>
            <tr>
                <td>Contact No:*</td><td><input type="text" id="txtNumber" name="txtNumber" value=""/></td>
            </tr>
            <tr>
                <td>Email-ID:*</td><td><input type="text" name="txtEmail" value=""/></td>
            </tr>
            <tr>
                <td>Password:*</td><td><input type="password" name="txtPassword" value=""/>(min. 6 characters)</td>
            </tr>
            <tr>
                <td>Upload Profile Image:</td><td><input type="file" name="profileImage"/></td>
            </tr>
            <tr>
                <td><input type="submit" name="submit" value="SUBMIT"/></td>
                <td><input type="reset" name="clear" value="CLEAR"/></td>
            </tr>
            </table>

            </form>
            </center>
    </body>
    </html>
0

hi broj1 i want to insert countryname in DB when submit the form..

and ya i cant change option value bcoz it affects on my ajax code..so plz tell me how to get country name from dropdown list

0

You need to tell me what are the fields $countryName[$i][0] and $countryName[$i][1] in the tabče county (the first two fields).

0

Sorry, disregard my last post, I see you already explained that.

Please post the addDetails.php page code too since everything is happening there.

0

Just my guess since I havent seen the code of the addDetails.php page: On addDetails.php you will get the ID of the country and this is the information you want to store so you do not need a country name at all (or do you?). In case you really need it you can put it in a hidden field on the previous page and it will be sent over to addDetails.php in the $_POST array. Hope this helps.

0

suppose table name is tblcourse and suppose i select course_code from the dropdown list then releted records will be automatically show the remainig textfeild like course_name,course_fee etc. how can it is possible in php?

0

<?php

<?php
                    $arr =array("this", "is", "the", "dropdown");
                    echo "<select name='image'>";
                    foreach($arr as $option){
                        echo "<option value='{$option}'>{$option}</option>";  
                    }
                    echo "</select>";
                    ?>


                echo "<select name='image'>";
                foreach($arr as $option){
                    echo "<option value='{$option}'>{$option}</option>";  
                }
                echo "</select>";
                ?> 
0
        function model(){
        $user= mysql_query("select * from product ");
        while($record=mysql_fetch_array($user))
        {
        echo'<option value="'.$record['model'] .'">'.$record['model'] .'</option>';
        }   
        } 

        <select name="cid" onChange="this.value" >
                    <option value="">Select Category:</option>
                        <?php model() ?>
                    </select>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.