Jump to content

Controls not working after form filled


jocast

Recommended Posts

Hello there,

I have a problem with a form, as soon as I fill the for using a query. The buttons doesn't work anymore. They work when i open the page, they have somoe js to emable and diable controls. but when i do a search and get the form filled, non of the controls work anymore. Any advise?

 

Link to comment
Share on other sites

Got code?

 

We could make theories all day but unless you've got something for us to look at we can't help you much.

 

Sounds like your having some js issues since your form is getting filled properly, and that's considering your using PHP for that. If it's dealing with js I'm not going to be of much help to you as I'm getting started with js.

Link to comment
Share on other sites

Here is my js code.

 

function OKPressed(){     

    var TextBox = document.getElementById('txtSearch').value;

    DisableControls('input','text',false);

    DisableControls('input','button',true);

    SwitchDisabled('btnOK');

  if (TextBox != "") {

    window.location = 'invoice_list2.php/?invid=' + TextBox;

    }else{

        window.location = 'invoice_list2.php';

    }

    }

 

And this are the 2 php functions i run after pressing OK

Function InvoiceSearch($invid){

    global  $row;

    $result = mysql_query("Select * from mytable

    where id = '$invid'") or trigger_error(mysql_error());

   

    if ($row = mysql_fetch_array($result)){

       

          return $row;

         

    }else {

    echo "<script>alert(" . $labels_array[invoicenf] . ");</script>";

    }

 

}

 

Function InvoiceDetailSearch($invid){

    global  $detailrow;

    $result = mysql_query("Select * from mytable2

    where id = '$invid'") or trigger_error(mysql_error());

    $detailrow = mysql_fetch_array($result);

    return $detailrow;

}

 

thank you for your help.

Link to comment
Share on other sites

Sorry I am new in php and a tutorial i saw uses them.

function SwitchDisabled(TextBoxID) {

            var TextBox = document.getElementById(TextBoxID);

 

   

            if (TextBox.disabled) {

                TextBox.disabled = false;

 

            }

            else {

                TextBox.disabled = true;   

            }

        }

 

function DisableControls(tagName,typeName,opDisable)

{

    var ControlsToDisable = document.getElementsByTagName(tagName);

 

    for (i = 0; i < ControlsToDisable.length; i++)

    {

        // if this input type is button, disable

        if (ControlsToDisable.type == typeName)

        {

            ControlsToDisable.disabled = opDisable;

        }

    }

}

Link to comment
Share on other sites

A lot of tutorials, unfortunately, rely on 'global'.  It's really the wrong way to go.  Functions have argument/parameter lists for a reason.  Pass everything your functions need to work through their lists.

 

In any event, what do you mean by your form being filled in by a query?  What's the process, step-by-step?  And, when should your button(s) be enabled?

Link to comment
Share on other sites

You are going to need to post enough of your code that demonstrates and reproduces the problem, i.e. your whole form page and any php pages that are referenced by that page. Just posting bits and pieces taken out of context doesn't help because that doesn't show how the code is being called or what it operates on.  xxxxxx out any sensitive information in your code, but to get the quickest solution, you need to post all the code that is relevant to this problem.

Link to comment
Share on other sites

here is my php

 

<HTML>
<HEAD>
<TITLE></TITLE>
<script src="jsFunctions.js" language="javascript" type="text/javascript"></script>

</HEAD>
<BODY onload="javascrypt:loadPressed();" >
<form name=form1 action="post">
    <div style="width:900px; margin-left: auto; margin-right:auto;font-size: small; ">

<?php

include('config.php');
include('header.php');
include('functions.php');
labels_language('eng');
InvoiceSearch($_GET['invid']);
InvoiceDetailSearch($_GET['invid']);
?>


    <h2><?php echo $labels_array[invoice_title] ?></h2>
    <input type="button" value="<?php echo $labels_array[newx] ?>" id="btnNew" style=" font-size: small;" onclick="javascript:NewPressed();"/>
    <input type="button" value="<?php echo $labels_array[edit] ?>" id="btnEdit" style=" font-size: small;" onclick="javascript:SwitchDisabled('txtName');" />
    <input type="button" value="<?php echo $labels_array[delete] ?>" id="btnDelete" style=" font-size: small;"/>
    <input type="button" value="<?php echo $labels_array[save] ?>" id="btnSave" style=" font-size: small;"onclick="javascript:SavePressed();"/>
    <input type="button" value="<?php echo $labels_array[cancel] ?>" id="btnCancel" style=" font-size: small;" onclick="javascript:CancelPressed();"/>
    <input type="button" value="<<" id="btnFirst" style=" font-size: small;"/>
    <input type="button" value="<" id="btnPrevious" style=" font-size: small;"/>
    <input type="button" value=">" id="btnNext" style=" font-size: small;"/>
    <input type="button" value=">>" id="btnLast" style=" font-size: small;"/>
    <input type="button" value="<?php echo $labels_array[search] ?>" id="btnSearch"  style="font-size: small;" onclick="javascript:SearchPressed();"/>
    <input type="text" value="" id="txtSearch" size="10px" style=" font-size: small;"/>
    <input type="button" value="<?php echo $labels_array[ok] ?>" id="btnOK" style=" font-size: small;" onclick ="javascript:OKPressed();"/>
    <table border="0" style="width:900px; margin-left: auto; margin-right:auto; text-align: right; font-size: small; " align="right">
        <thead>
            <tr>
                <th>    </th>
                <th>    </th>
                <th><?php echo $labels_array[date]; ?>: <input type="text" id="txtDate" value="" size="10px" /> </th>
                <th><?php echo $labels_array[id] ?>: <input type="text" id="txtID" value="" size="10px" readonly /></th>
            </tr>
        </thead>
    </table>


    <table border="0" style="width:900px; margin-left: auto; margin-right:auto; font-size: small;">
        <thead align="left">
            <tr>
                <th><?php echo $labels_array[soldto] ?></th>
                <th><?php echo $labels_array[shipto] ?></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td><?php echo $labels_array[name] ?>: <input type="text"   id="txtName" value="<?php echo $row['name'] ?>" /></td>
                <td><?php echo $labels_array[name] ?>: <input type="text" id="txtName2" value="<?php echo $row['name2'] ?>" /></td>
            </tr>
            <tr>
                <td><?php echo $labels_array[addr1] ?>: <input type="text" id="txtAddr1" value="<?php echo $row['address1'] ?>" /></td>
                <td><?php echo $labels_array[addr1] ?>: <input type="text" id="txtAddr12" value="<?php echo $row['address12'] ?>" /></td>
            </tr>
            <tr>
                <td><?php echo $labels_array[addr2] ?>: <input type="text" id="txtAddr2" value="<?php echo $row['address2'] ?>" /></td>
                <td><?php echo $labels_array[addr2] ?>: <input type="text" id="txtAddr22" value="<?php echo $row['address22'] ?>" /></td>
            </tr>
            <tr>
                <td><?php echo $labels_array[city] ?>: <input type="text" id="txtCity" value="<?php echo $row['city'] ?>" /></td>
                <td><?php echo $labels_array[city] ?>: <input type="text" id="txtCity2" value="<?php echo $row['city2'] ?>" /></td>
            </tr>
            <tr>
                <td><?php echo $labels_array[state] ?>: <input type="text" id="txtState" value="<?php echo $row['state'] ?>" size="5px" /> <?php echo $labels_array[zip] ?>: <input type="text" id="txtZip" value="<?php echo $row['zip'] ?>" size="5px" /></td>
                <td><?php echo $labels_array[state] ?>: <input type="text" id="txtState2" value="<?php echo $row['state2'] ?>" size="5px" /> <?php echo $labels_array[zip] ?>: <input type="text" id="txtZip2" value="<?php echo $row['zip2'] ?>" size="5px" /></td>
            </tr>
        </tbody>
    </table>



<?php echo $labels_array[reference] ?>: <input type="text" id="txtPO" value="<?php echo $row['reference'] ?>" size="10px" />
<?php echo $labels_array[payterms] ?>: <input type="text" id="txtPayt" value="<?php echo $row['payterms'] ?>" size="10px" />
<?php echo $labels_array[status] ?>: <input type="text" id="txtStatus" value="<?php echo $row['status'] ?>" size="10px" />
<br/>
<br/><table border="1" style="width:900px; margin-left: auto; margin-right:auto; font-size: small;">
    <thead>
        <tr>
            <th><?php echo $labels_array[productcode] ?></th>
            <th><?php echo $labels_array[desc] ?></th>
            <th><?php echo $labels_array[qty] ?></th>
            <th><?php echo $labels_array[uom] ?></th>
            <th><?php echo $labels_array[price] ?></th>
            <th><?php echo $labels_array[disc] ?></th>
            <th><?php echo $labels_array[amount] ?></th>
            <th>+/-</th>
        </tr>
    </thead>
    <tbody>
    

        <br/>
        <?php

                    echo "<tr>";
                    echo "<td>" . $detailrow['codprod'] . "</td>";
                    echo "<td>" . $detailrow['proddescription'] . "</td>";
                    echo "<td>" . $detailrow['qty'] . "</td>";
                    echo "<td>" . $detailrow['code'] . "</td>";
                    echo "<td>" . $detailrow['price'] . "</td>";
                    echo "<td>" . $detailrow['discount'] . "</td>";
                    echo "<td>" . $detailrow['amount'] . "</td>";
                    echo "<td><input type='button' value='-' id='btnDel' size='10px'/></td>";
                    echo "</tr>";
        ?>
        <tr>
            <td><input type="text" id="txtProduct" value="" size="10px" /></td>
            <td><input type="text" id="txtDesc" value="" size="45px" readonly/></td>
            <td><input type="text" id="txtQty" value="" size="2px"/></td>
            <td><input type="text" id="txtUOM" value="" size="1px" readonly/></td>
            <td><input type="text" id="txtPrice" value="" size="4px" readonly/></td>
            <td><input type="text" id="txtDisc" value="" size="2px"/></td>
            <td><input type="text" id="txtAmount" value="" size="5px" readonly/></td>
            <td><input type="button" value="+" id="btnAdd" size="10px"/></td>
        </tr>
    </tbody>
</table>
<table style="width:900px; margin-left: auto; margin-right:auto; font-size: small;">
    <tbody>
        <tr>
            <td><?php echo $labels_array[totalletter] ?></td>
            <td></td>
            <td align="right"><?php echo $labels_array[subtotal] ?></td>
            <td><input type="text" id="txtSubTotal" value="<?php echo $row['sub-total'] ?>" size="10px" readonly/></td>
        </tr>
        <tr>
            <td><input type="text" id="txtTotletter" value="" size="50px" readonly/></td>
            <td></td>
            <td align="right"><?php echo $labels_array[descglob] ?> <input type="text" id="txtTotDisc" value="<?php echo $row['discount'] ?>" size="3px" readonly/>%   <?php echo $labels_array[amount] ?></td>
            <td><input type="text" id="txtDiscAmount" value="" size="10px"/></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td align="right"><?php echo $labels_array[totalnet] ?></td>
            <td><input type="text" id="txtTotAmount" value="" size="10px" readonly/></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td align="right"><?php echo $labels_array[tax] ?> <input type="text" id="txtTax" value="<?php echo $row['rate'] ?>" size="3px" readonly/>%   <?php echo $labels_array[amount] ?></td>
            <td><input type="text" id="txtTaxAmount" value="" size="10px"/></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td align="right"><?php echo $labels_array[total] ?></td>
            <td><input type="text" id="txtGrandTotal" value="<?php echo $row['total']; ?>" size="10px" readonly/></td>
        </tr>
    </tbody>
</table>


</div>
    </form>
</BODY></HTML>

 

Here is my php functions page

<?php
    function labels_language($language){
    if ($language == 'esp') {
      global  $labels_array;
        $labels_array= array(
                'id' => 'FOLIO',
                'name' => 'NOMBRE',
                'subtotal' =>'SUB-TOTAL',
                'invoice_title' => 'Facturacion Electronica',
                'newx'=>'NUEVO',
                'edit'=>'MODIFICAR',
                'delete'=>'ELIMINAR',
                'cancel'=>'CANCELAR',
                'save'=>'GUARDAR',
                'search'=>'BUSCAR',
                'ok'=>'OK',
                'soldto'=>'SOLD TO',
                'shipto'=>'SHIP TO',
                'addr1'=>'DIRECCION',
                'addr2'=>'DIRECCION2',
                'city'=>'CIUDAD',
                'state'=>'EDO.',
                'zip'=>'CP',
                'reference'=>'NO. REFERENCIA',
                'payterms'=>'TERMINOS',
                'status'=>'ESTATUS',
                'date'=>'FECHA',
                'productcode'=>'CDOPROD',
                'desc'=>'DESCRIPCION',
                'qty'=>'CANT',
                'uom'=>'UDM',
                'price'=>'PRECIO',
                'disc'=>'DESC%',
                'amount'=>'MONTO',
                'descglob'=>'DESCUENTO GLOBAL',
                'totalnet'=>'TOTAL NETO',
                'tax'=>'IVA',
                'totalletter'=>'TOTAL LETRA',
                'total'=>'TOTAL',
                'invoicenf' => 'FACTURA NO EXISTE',
                'barcode' => 'CODIGO DE BARRAS');
    }
    if ($language == 'eng'){
         global  $labels_array;
        $labels_array= array(
                'id' => 'INVOICE NO.',
                'name' => 'NAME',
                'subtotal' =>'SUB-TOTAL',
                'invoice_title' => 'Invoicing',
                'newx'=>'NEW',
                'edit'=>'EDIT',
                'delete'=>'DELETE',
                'cancel'=>'CANCEL',
                'save'=>'SAVE',
                'search'=>'SEARCH',
                'ok'=>'OK',
                'soldto'=>'SOLD TO',
                'shipto'=>'SHIP TO',
                'addr1'=>'ADDRESS',
                'addr2'=>'ADDRESS2',
                'city'=>'CITY',
                'state'=>'ST.',
                'zip'=>'ZIP',
                'reference'=>'REFERENCE NO.',
                'payterms'=>'PAY TERMS',
                'status'=>'STATUS',
                'date'=>'DATE',
                'productcode'=>'PRODCODE',
                'desc'=>'DESCRIPTION',
                'qty'=>'QTY',
                'uom'=>'UOM',
                'price'=>'PRICE',
                'disc'=>'DISC%',
                'amount'=>'AMOUNT',
                'descglob'=>'GLOBAL DISCOUNT',
                'totalnet'=>'NET TOTAL',
                'tax'=>'TAX',
                'totalletter'=>'TOTAL WORDS',
                'total'=>'TOTAL',
                ''=>'',
                'barcode' => 'BARCODE',
                'invoicenf' => 'INVOICE DO NOT EXISTS'
            );
    }
    return $labels_array;
    }

Function InvoiceSearch($invid){
    global  $row;
    $result = mysql_query("select ig.id, ig.adddate, cu.name,cu.address1, cu.address2,
            cu.city, cu.state, cu.zip, sh.name as name2,sh.address1 as address12,
            sh.address2 as address22, sh.city as city2, sh.state as state2,
            sh.zip as zip2,reference, pt.description as payterms,st.desc as status,`barcode-img`,
            `sub-total`, discount,tx.rate,total
    from invoice_general ig
    left outer join payterms pt on pay_terms = pt.id
    left outer join status st on status = st.id
    left outer join taxrate tx on taxrate = tx.id
    left outer join customers cu on customer = cu.id
    left outer join customers sh on shipto = sh.id
    where ig.id = '$invid'") or trigger_error(mysql_error());
    
    if ($row = mysql_fetch_array($result)){
        
           return $row;
           
    }else {
     echo "<script>alert(" . $labels_array[invoicenf] . ");</script>";
    }

}

Function InvoiceDetailSearch($invid){
    global  $detailrow;
    $result = mysql_query("SELECT  p.code as codprod, p.description as proddescription, qty, uom.code, invd.price, invd.discount, invd.amount
    FROM invoice_detail invd
    left outer join products p on invd.`product-id` = p.id
    LEFT OUTER JOIN uom ON invd.uom = uom.id
    where invd.`invoice-id` = '$invid'") or trigger_error(mysql_error());
    //$detailrow = mysql_fetch_array($result);
    $detailrow = mysql_fetch_array($result);
    return $detailrow;
}

?>

 

And here is my js funtions page

function SwitchDisabled(TextBoxID) {
            var TextBox = document.getElementById(TextBoxID);

     
            if (TextBox.disabled) {
                TextBox.disabled = false;

            }
            else {
                TextBox.disabled = true;     
            }
        }

function DisableControls(tagName,typeName,opDisable)
{
    var ControlsToDisable = document.getElementsByTagName(tagName);

    for (i = 0; i < ControlsToDisable.length; i++)
    {
        // if this input type is button, disable
        if (ControlsToDisable[i].type == typeName)
        {
            ControlsToDisable[i].disabled = opDisable;
        }
    }
}


function AssignValue(tagName,typeName,Value)
{
    var ControlsToDisable = document.getElementsByTagName(tagName);

    for (i = 0; i < ControlsToDisable.length; i++)
    {
        if (ControlsToDisable[i].type == typeName)
        {
            ControlsToDisable[i].value = Value;
        }
    }
}
function loadPressed(){
    DisableControls('input','text',true);
    DisableControls('input','button',false);
    SwitchDisabled('btnSave');
    SwitchDisabled('btnCancel');
    SwitchDisabled('txtSearch');
}
function NewPressed(){
    window.location = 'invoice_list2.php'
    DisableControls('input','text',false);
    DisableControls('input','button',true);
    SwitchDisabled('btnSave');
    SwitchDisabled('btnCancel');
    SwitchDisabled('txtSearch');
    Switchdisables('btnAdd');
}
function CancelPressed(){
    SavePressed();
    AssignValue('input','text','');
}
function SavePressed(){
    DisableControls('input','text',true);
    DisableControls('input','button',false);
    SwitchDisabled('btnCancel');
    SwitchDisabled('btnSave');
    SwitchDisabled('txtSearch');
}
function SearchPressed(){
    DisableControls('input','text',false);
    DisableControls('input','button',true);
    SwitchDisabled('btnOK');
}
function OKPressed(){       
    var TextBox = document.getElementById('txtSearch').value;
    DisableControls('input','text',false);
    DisableControls('input','button',true);
    SwitchDisabled('btnOK');
   if (TextBox != "") {
    window.location = 'invoice_list2.php/?invid=' + TextBox;
    }else{
        window.location = 'invoice_list2.php';
    }
    
}

Link to comment
Share on other sites

You have a spelling error at the beginning of your PHP file.  javascrypt should be javascript.

 

Does the problem happen just after the OK button is pressed?  After any button is pressed?  Have you tried it with other browsers?  Have you seen any JavaScript errors?

Link to comment
Share on other sites

It happens after i got results from sql and fill the form with them. If i press OK with an invalid invoice number nothing happens, but i try with a valid number it displays the values then the buttons do not work anymore. In other browsers i see an alert "undefined" if i do not enter a invoice number in firefox i got no errors

 

Link to comment
Share on other sites

The 'undefined' means you have an error.  Specifically, your JavaScript is most likely trying to manipulate a DOM object it cannot find/doesn't exist.  It's a common error as JavaScript runs faster than HTML in the browser, so often scripts try to obtain references to HTML elements which haven't been rendered yet.  The problem is trying to pinpoint the source of the error.

 

Your best bet is to redesign your pages/site.  Use unobtrusive JavaScript techniques (google it) and be sure to wait until the DOM loads fully before attempting to run any JS.  Finally, develop using Firefox and the Firebug plugin.  It's invaluable as a development tool, especially when it comes to debugging JS.

Link to comment
Share on other sites

Found the error!!!

It was my js declaration

 

<script src="jsFunctions.js" language="javascript" type="text/javascript"></script>

 

Changed to

<script src="/myproject/jsFunctions.js" language="javascript" type="text/javascript"></script>

and now it works fine. because i gues it was trying to reac

/myproject/invoice_list2.php/jsFunctions.js after I posted the value /myproject/invoice_list2.php/?invid=1

is there a way to avoid this, or using a full path is the correct way?

 

Thank you

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.