1,105,546 Community Members

getting the select value

Member Avatar
titosd
Junior Poster in Training
69 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
AARTI SHRIVAS
Posting Pro in Training
410 posts since Dec 2012
Reputation Points: 2 [?]
Q&As Helped to Solve: 38 [?]
Skill Endorsements: 3 [?]
 
0
 
    <?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

Member Avatar
titosd
Junior Poster in Training
69 posts since Jan 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 85 [?]
Q&As Helped to Solve: 86 [?]
Skill Endorsements: 9 [?]
 
1
 

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';
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article