Hello,

I want ask you, how can i get the value of the select in the same page to use it to loop by it ?

for example:

<select name="abc">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
</select>

and to use the $_POST['abc'] in a loop
like this:

for($i=0;$<$_POST['abc'];$i++){
    echo $i;
}

If you have another way to get the value except the AJAX because i tried it and not succedded

Thanks

Recommended Answers

All 3 Replies

    <?php 
    $abc="";
    if(isset($_POST['sub']))
    {
        $abc=$_POST['abc'];
        echo $abc;
    }

    ?>

    <select name="abc">
    <option value="1" >1</option>
    <option value="2" >2</option>
    <option value="3" >3</option>
    </select>
    <input type='submit' name='sub'>

try this

but with this code i can't get the value of the select without submitting the form, and i want to get it before this cause i want to use this vlaue in the same form before i submit it

theres a way around ajax for non changing data - which is preloading the data.

<script type='text/javascript'>
var abcData = new Array();
<?php
$data = array(
            '1'=>array('id'=>'1','description'=>'desc 1'),
            '2'=>array('id'=>'2','description'=>'desc 2'),
            '3'=>array('id'=>'3','description'=>'desc 3')
        );
foreach($data as $v){
    echo "abcData[{$v['id']}] = 'option {$v['id']} data: {$v['description']}';\r\n";
}
?>
function updateView(obj){
    var target = document.getElementById('abcBoxData');
    target.innerHTML = abcData[obj.value];
}
</script>

<select id='abcBox' name='abc' onchange='updateView(this)'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
<div id='abcBoxData'></div>
<script type='text/javascript'>
updateView(document.getElementById('abcBox'));
</script>

It literally just get php to hard code the data into javascript on page load:

var abcData = new Array();
abcData[1] = 'option 1 data: desc 1';
abcData[2] = 'option 2 data: desc 2';
abcData[3] = 'option 3 data: desc 3';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.