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++) {..}

Link to comment
Share on other sites

you must give that input (and any other input you plan on using), a name, ie.

<input type="text" name="number" value="32" />

*replace "number" with whatever you want.

 

btw, HTML prefers double-quotes (") as opposed to single-quotes (').

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.