evz0001 Posted April 4, 2008 Share Posted April 4, 2008 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; } } ?> ----------------------------------------------------- Quote Link to comment https://forums.phpfreaks.com/topic/99543-passing-radio-button-status-once-data-is-fetched/ Share on other sites More sharing options...
we4freelance Posted April 6, 2008 Share Posted April 6, 2008 Hello, Please change your code for script that fetch data with following code. <?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"; echo "document.clientForm.edit.disabled = no;"; echo "document.clientForm.delete.disabled = no;"; }else{ echo "document.clientForm.add.disabled = no;"; } } ?> Hope this will solve your problem; Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/99543-passing-radio-button-status-once-data-is-fetched/#findComment-510463 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.