Jump to content

evz0001

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

evz0001's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have 2 files that does the following: - 1 x form that uses ajax to fetch name & last name once id number has been input. - 1 x script that passes the info from database to form above My problem is: If the data is available (caus of valid id number) I want to activate (enable) the edit & delete radio button on the form else if the id number isn't valid I want to enable the add radio button. Thanks ---------------------------------------------------- Code for the form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <style type="text/css"> body{ background-repeat:no-repeat; font-family: Trebuchet MS, Lucida Sans Unicode, Arial, sans-serif; height:100%; background-color: #FFF; margin:0px; padding:0px; background-image:url('/images/heading3.gif'); background-repeat:no-repeat; padding-top:85px; } fieldset{ width:500px; margin-left:10px; } </style> <script type="text/javascript" src="js/ajax.js"></script> <script type="text/javascript"> /************************************************************************************************************ Ajax client lookup Copyright © 2006 DTHMLGoodies.com, Alf Magne Kalleland This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Dhtmlgoodies.com., hereby disclaims all copyright interest in this script written by Alf Magne Kalleland. Alf Magne Kalleland, 2006 Owner of DHTMLgoodies.com ************************************************************************************************************/ var ajax = new sack(); var currentClientID=false; function getClientData() { var clientId = document.getElementById('clientID').value.replace(/[^0-9]/g,''); if(clientId.length==13 && clientId!=currentClientID){ currentClientID = clientId ajax.requestFile = 'getClient.php?getClientId='+clientId; // Specifying which file to get ajax.onCompletion = showClientData; // Specify function that will be executed after file has been found ajax.runAJAX(); // Execute AJAX function } } function showClientData() { var formObj = document.forms['clientForm']; eval(ajax.response); } function initFormEvents() { document.getElementById('clientID').onblur = getClientData; document.getElementById('clientID').focus(); } window.onload = initFormEvents; </script> </head> <body> <form name="clientForm" action="ajax-client_lookup.html" method="post"> <fieldset> <legend><b>ID Number</b></legend> <table> <tr> <td><label for="clientID">ID number:</label></td> <td><input name="clientID" id="clientID" size="13" maxlength="13"></td> </tr> <tr> <td><label for="firstname">First name:</label></td> <td><input name="firstname" id="firstname" size="20" maxlength="255" disabled="Yes"></td> </tr> <tr> <td><label for="lastname">Last name:</label></td> <td><input name="lastname" id="lastname" size="20" maxlength="255" disabled="Yes"></td> </tr> </table> <p> <input name="add" type="radio" value="add_contact" disabled="yes"> Add Contact<br> <input name="edit" type="radio" value="edit_contact" disabled="yes"> Edit Contact<br> <input name="delete" type="radio" value="delete_contact" disabled="yes"> Delete Contact</p> </fieldset> </form> </body> </html> ---------------------------------------------------- code for script that fetch data <?php if(isset($_GET['getClientId'])){ $res = mysql_query("select * from contacts where idnumber='".$_GET['getClientId']."'") or die(mysql_error()); if($inf = mysql_fetch_array($res)){ echo "formObj.firstname.value = '".$inf["firstname"]."';\n"; echo "formObj.lastname.value = '".$inf["lastname"]."';\n"; document.clientForm.edit.disabled = no; document.clientForm.delete.disabled = no; }else{ document.clientForm.add.disabled = no; } } ?> -----------------------------------------------------
  2. Hi there, Do you have sample code for above topic as I'm using PHP & MySQL.  I need to to generate a second drop down list in the same form.  The values of this 2nd d-down are based on the value of the 1st. TA Eugene
×
×
  • 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.