moses saleh
moses saleh

Reputation: 91

Select value from selectbox in the same page

When I open my page, $d = " " and when I select a value from selectbox, should $d = selected value. How can I set $d = selected value When I click on the button?

<?php
if ($rows['plus'] < $Stime OR $rows['plus'] == 0) {
    $saveal = mysql_query("UPDATE `".TB_PREFIX."users` SET plus = 0 WHERE id = \"".$userid."\"");
    echo "<b>غير مفعّل</b> ";
    $activ = array('يوم','يومان','3 أيام','4 أيام','5 أيام','6 أيام','7 أيام');
?> 
    <select name="select_day"><option value="" >---</option>
<?php
        foreach($activ as $key => $value):
        echo '<option value="'.$key.'">'.$value.'</option>'; //close your tags!!
        endforeach;

        ?>
    </select>

<?php

} elseif ($rows['plus'] > 0) {
    echo "<b>مفعّل</b>";
}
?>
<input type="submit" name="activ_plus" value="تفعيل" onclick="<?php
            if ($_POST['select_day'] = "يوم") {
                $d = 6644555;
                $saveal2 = mysql_query("UPDATE `".TB_PREFIX."users` SET plus = \"".$d."\" WHERE id = \"".$userid."\"");
            }
?>">

Upvotes: 0

Views: 59

Answers (1)

mboyde
mboyde

Reputation: 69

If I am not mistaken, this would be much easier to accomplish through Javascript or jQuery. For example, in jQuery, a thing that you could do is:

$('#selectBox').change(function(){
var selectValue = $('#selectBox').val();
if(selectValue == 'stringText'){
    $('#textBox').val('something');
}
});

This is simply a very routine function/idea that you can use in jQuery. If the page loads a value for the select box (ex: somthing retrieved from the database) then you can use php through the $rows['selectValue'] from a query to load a certain value in other form fields. If you are trying to submit the form through "onClick", you need to stop writing new code and read up on either AJAX OR the proper way to submit data using php.

Upvotes: 1

Related Questions