cordoprod Posted February 5, 2009 Share Posted February 5, 2009 Hi. I want to do something with my form. It's a thing for getting where we live. Like this: TEXTFIELD *hidden span which is going to appear when postal code is entered* I want to be able to add the postal code to a textfield. And then i have a hidden span which is going to appear when the postal code is entered. What is going to appear in the span is from a database: Here is my code: ajax.php if($_GET['action'] == 'bosted') { $db = new DbConnector(); $db->connect(); $sql = "SELECT * FROM postnummer WHERE postnummer='".$_REQUEST['postnummer']."'"; $fetch = $db->fetchArray($db->query($sql)); echo $fetch['fylke'].", ".$fetch['kommune']; } register.php <script language="javascript" type="text/javascript"> <!-- //Browser Support Code function ajaxFunction(){ var ajaxRequest; try{ ajaxRequest = new XMLHttpRequest(); } catch (e){ try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Bytt nettleser!"); return false; } } } ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ document.getElementById('postbox').text = ajaxRequest.responseText; } } ajaxRequest.open("GET", "ajax.php?action=bosted&postnummer=".$("#password").val();."", true); ajaxRequest.send(null); } //--> </script> <label> <input name="reg_postnummer" type="text" id="reg_postnummer" size="4" onChange="ajaxFunction();"> </label> <span id="postbox"></span> Link to comment https://forums.phpfreaks.com/topic/143956-solved-php-and-ajax-help/ Share on other sites More sharing options...
grim1208 Posted February 5, 2009 Share Posted February 5, 2009 What is it you are asking help with? Are you getting errors? Be a bit more specific Link to comment https://forums.phpfreaks.com/topic/143956-solved-php-and-ajax-help/#findComment-755388 Share on other sites More sharing options...
rhodesa Posted February 5, 2009 Share Posted February 5, 2009 this piece of code leads me to believe you are using a JS library (like jQuery): $("#password").val() if so, you should use the AJAX functions in that library to make your life a lot easier Link to comment https://forums.phpfreaks.com/topic/143956-solved-php-and-ajax-help/#findComment-755391 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.