0

I am a VB.net programmer and I am very new to PHP HTML and Java Scripts

I am doing a project for my company using PHP HTML and Java Scripts and I want to Know how to make readonly a text box after it gets the input

This text box should first get the input and based on that input display other data to the user then it should be read only because it is the key field for the other displayed information

I used javascripts to readonly the textbox but from that point onwards the page displays the following errors

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\includes\form_functions.php on line 15

Notice: Undefined index: RunningNo in H:\wamp\www\OCBS\EditRun.php on line 63

where RunningNo is the name of the textbox

Please Help me

God Bless
Thanks
Eranga.

3
Contributors
10
Replies
21
Views
6 Years
Discussion Span
Last Post by ErangaD
0

There may be an easier way, but one solution might be to do it through a form.

Set up a form with the text area you are referring to. To make the text box read-only it would be:

<textarea name="example" cols="45" rows="5" readonly="readonly" id="example"></textarea>

Make the form submit to itself so that it just refreshes with the new posts and make the value of the text area equal to $_POST

Set up an if statement before hand that checks to see whether the textarea has been posted and if so, it adds the readonly to the tag. Else it is editable.

makes sense I hope.

0

When I make the textbox readonly as u said I cant input any value to it

0

right, you need an if statement:

<?php if(isset($_POST['example'])) { echo "readonly=\"readonly\""; } ?>

that would be inside your text area tag in the form. So if you have not posted to the text area, it is editable. Maybe I do not understand your problem?

Edited by megachip04: n/a

0

when I used your above code the following error came
Parse error: parse error in H:\wamp\www\OCBS\EditRun.php on line 66

please help me I am very new to PHP

please send me the full if statement

thank you
God Bless

Eranga

0

the if statement needs and extra ". I updated the post above...

can you post your form code?

Edited by megachip04: n/a

0
<?php require_once("includes/session.php"); ?>
<?php //require_once("includes/connection.php");
?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in();?>


    <script type="text/javascript">
        function validateForm()
        {
        var x=document.forms["EditRun"]["RunningNo"].value
        if (x==null || x=="")
            {
                alert("Running No is a Required Field");
                document.getElementById("RunNo").focus();
                return false;
            }
        else
            {
            }
        if ( isNaN (x)==true)
            {
                alert("Running No should be Numeric");
                document.getElementById("RunNo").focus();
                document.getElementById("RunNo").select();
                return false;
            }
        else
            {
            }
            document.getElementById("RunNo").disabled = true    
        }
    </script>
    <script type="text/javascript">
    function dodisable()
    {
        document.getElementById("RunNo").disabled = true;
        alert("R----------------------");
    }
    </script>
    <?php
            //document.getElementById("RunNo").setAttribute("readonly", "true");
            //document.getElementById("RunNo").disabled = true;
            //document.getElementById("RunNo").readOnly="readonly";
            //document.forms["EditRun"]["RunningNo"].disabled="true";
            //document.getElementById('RunNo').readOnly=true;
    ?>

<?php
    include_once("includes/form_functions.php");

    // START FORM PROCESSING
    if (isset($_POST['submit1'])) { // Form has been submitted.
        $errors = array();

        // perform validations on the form data
        $required_fields = array('RunningNo');
        $errors = array_merge($errors, check_required_fields($required_fields, $_POST));

        $fields_with_lengths = array('RunningNo' => 10);
        $errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));

        $username = trim(odbc_prep($_POST["RunningNo"]));
        $ScanVal = "";
        $ScanItm =  "";
        if(isset($_POST['RunningNo'])) { echo "readOnly=\"readoOnly\""; } 
        //javascript to read
        //echo "<SCRIPT LANGUAGE='javascript'>dodisable();</SCRIPT>";
        //echo "<script>dodisable();</script>";
        //'echo "<input type='text' id='RunNo' name='RunningNo' readonly>"'
        //echo 'onclick="return dodisable()"';
        //echo '<input type="text"  id="RunNo" name="RunningNo"/>'

        //<script language = 'javascript'>
        //  alert('Congrats');
        //</script>      
        //print('<script language = "javascript">
        //      document.getElementById("RunNo").readOnly="readonly";
        //</script>');

        //exit();

        //$message1 =strlen($username);


        //----------------------------form validation 2-------------------------
        //if (!is_numeric($username)) {
            //$message = "Input should be a Numeric Value";
            ////$username = trim(odbc_prep($_POST['RunningNo']));
            //redirect_to("EditRun.php");

        //} 
        //-------------------------------------
        //$hashed_password = sha1($password);
        //exit("unable to open file ");

        if ( empty($errors) ) {
            // Check database to see if username and the hashed password exist there.

            // 1. Create a database connection
            // 2. Select a database to use and Open Connection
            $conn=odbc_connect('MasterDB','','');
            if (!$conn)
              {exit("Connection Failed: " . $conn);}
            // 3. Perform database query
            $sql="SELECT [Running No], [Scanned Value], [No of Scanned Items] FROM [2Batch Details DB-Scan] WHERE [Running No]={$username}";

            $result_set=odbc_exec($conn,$sql);
            if (odbc_fetch_row($result_set) == 1) {
                $username =  odbc_result($result_set,"Running No");
                $ScanVal =  odbc_result($result_set,"Scanned Value");
                $ScanItm =  odbc_result($result_set,3);

                //redirect_to("EditDtl.php");
            }   
            elseif (odbc_fetch_row($result_set) == 0){
                $message = "No Record found for Running No ".$username;
            }
            else {
                // username/password combo was not found in the database
                $message = "There is more than One Record .<br />
                    for Running No ".$username;
                }
                //5. Close connection
                odbc_close($conn);
        } else {
            if (count($errors) == 1) {
                $message = "There was 1 error in the form.";
            } else {
                $message = "There were " . count($errors) . " errors in the form.";
            }
        }
    }
    elseif (isset($_POST['submit2']))
    //elseif($_REQUEST['submit2'] == 'Update')
    {
            // 1. Create a database connection
            // 2. Select a database to use and Open Connection
            $conn=odbc_connect('MasterDB','','');
            if (!$conn)
              {exit("Connection Failed: " . $conn);}

              $username=trim(odbc_prep($_POST['RunningNo']));
              $ScanVal=trim(odbc_prep($_POST['ScanVal']));
              $ScanItm =trim(odbc_prep($_POST['ScanItm']));
                        // 3. Perform database query
            $sql="UPDATE [2Batch Details DB-Scan] SET [Scanned Value]='$ScanVal', [No of Scanned Items]='$ScanItm' WHERE [Running No]={$username}";
            $result_set=odbc_exec($conn,$sql);
            $message = odbc_num_rows($result_set) . " Row Afected.";
            $username="";
            $ScanVal="";
            $ScanItm=""; 
            //5. Close connection
            odbc_close($conn);

    }else { // Form has not been submitted.
        if (isset($_GET['logout']) && $_GET['logout'] == 1) {
            $message = "You are now logged out.";
        }
        //$message = "You are now logged out.";
        $username = "";
        $ScanVal = "";
        $ScanItm =  "";
    }

?>

<?php //include("includes/header-1.php");
?>
<html>
    <head>
        <title>OCBS</title>
        <link href="stylesheets/public.css" media="all" rel="stylesheet" type="text/css" />
        <script type="text/javascript">
        function setFocus()
        {
            document.getElementById("RunNo").focus();
        }
        </script>
    </head>
    <body  onload="setFocus()">

        <div id="header">
            <h1>Outward Clearing Balancing System(OCBS)</h1>
        </div>
        <div id="main">

<table id="structure">
    <tr>
        <td id="navigation">
            <li><a href="index.php">Return to Main Menu</a></li>
        </td>
        <td id="page">
            <h2>Edit Details</h2>
            <?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
            <?php //if (!empty($message)) {echo "<p class=\"message\">" . $message1 . "</p>";}
            ?>
            <?php if (!empty($errors)) { display_errors($errors); } ?>
            <form action="EditRun.php" name="EditRun" method="post">
            <table>
                <tr>
                    <td>Running No:</td>
                    <td><input type="text"  id="RunNo" name="RunningNo" maxlength="10"  value="<?php echo htmlentities($username); ?>" /></td>
                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="submit1" value="Proceed" onclick="return validateForm()" /></td>
                </tr>
                    <td>Sacnned Value:</td>
                     <td><input type="text"  id="Val" name="ScanVal" maxlength="10" value="<?php echo htmlentities($ScanVal); ?>" /></td>
                    <td>Sacnned Items:</td>
                    <td><input type="text"  id="Itm" name="ScanItm" maxlength="10" value="<?php echo htmlentities($ScanItm); ?>" /></td>

                </tr>
                <tr>
                    <td colspan="2"><input type="submit" name="submit2" value="Update" /></td>
                </tr>
            </table>
            </form>
        </td>
    </tr>
</table>
<?php include("includes/footer.php"); ?>

Edited by pyTony: fixed formatting

0
<form action="EditRun.php" name="EditRun" method="post">
<table>
<tr>
<td>Running No:</td>
<td><input type="text" id="RunNo" name="RunningNo" maxlength="10" value="<?php echo htmlentities($username); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit1" value="Proceed" onclick="return validateForm()" /></td>
</tr>
<td>Sacnned Value:</td>
<td><input type="text" id="Val" name="ScanVal" maxlength="10" value="<?php echo htmlentities($ScanVal); ?>" /></td>
<td>Sacnned Items:</td>
<td><input type="text" id="Itm" name="ScanItm" maxlength="10" value="<?php echo htmlentities($ScanItm); ?>" /></td>

</tr>
<tr>
<td colspan="2"><input type="submit" name="submit2" value="Update" /></td>
</tr>
</table>
</form>

in this form. Do determine whether the text box will be readonly or not and to insert the value, insert this code into whichever input tag you are refering to

<?php if(isset($_POST['RunNo'])) {
echo "readonly=\"readonly\" value=\"$_POST['RunNo']\"";
?>

This will cause the form to display the submitted information in a readonly fashion, only if the user has submitted the information.
"RunNo" can be replaced by whatever the id is of the input you are using.

Edited by megachip04: n/a

0

I used your code and it works
Thanks a lot

Can I know how to Exit PHP if some conditions are met (That is at certain point of the code exit PHP without executing the rest of the code
Like Exit Sub in Visual Basic .Net

Thanks
God Bless

Eranga

0
exit; //unconditional exit
if(condition) exit; // if the condition is met just exit
if(condition) die('a horrible death'); //exit with a string error message printed (die is synonym for exit)
if(condition) { huge mass of code;
exit(112); } //execute a huge mass of code, then exit with a numeric error message

or any combination of the above
When in doubt RTFM
or Let me Google that for you

Edited by almostbob: n/a

0

Thanks for the code

when I use these codes the current page goes blank (all the controls and colours are hidden
How can I exit PHP and remain on the same page without it going Blank

Thanks
God Bless

Eranga

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.