We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,657 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

getting the select value

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

3
Contributors
3
Replies
1 Hour
Discussion Span
3 Months Ago
Last Updated
4
Views
titosd
Junior Poster in Training
69 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 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

arti18
Posting Whiz in Training
206 posts since Dec 2012
Reputation Points: 2
Solved Threads: 25
Skill Endorsements: 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

titosd
Junior Poster in Training
69 posts since Jan 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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';
Biiim
Posting Pro
504 posts since Oct 2011
Reputation Points: 104
Solved Threads: 83
Skill Endorsements: 7

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1283 seconds using 2.72MB