Jump to content

Get value from a input with php


tphgangster

Recommended Posts

Ok..

 

lets say i have <input type='text' value='32' />

 

How do i get 32 from that input so that i can use it in a loop, a php function, anything.

 

exampel

for($i=0;$i<=$value;$i++) {..}

where $value is the value thats in the above input (32).

for($i=0;$i<=32;$i++) {..}

You need to use it from a POST operation. So, when the user enters the value and presses a button, you grab the value from the post values.

 

Also, assume that the input field is defined as so:

 

<form action= <?php echo $_SESSION['http'].$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?>
    <input name="txtVal" type="desc" id="txtval" size="15"> 
    <input type="submit" name="btnProc" value="Process">
</form>

 

if(isset($_POST['btnProc']) && $_POST['btnProc']=='Process'){
    $value=(isset($_POST['txtVal'])?$_POST['txtVal']:0);
    if($value>0){
        for($i = 0; $i<=$value; $i++) {
            echo $i.', ';
        }
    }
}

 

If you want it to work without the post form (form reload), then use javascript.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.