Jump to content

[SOLVED] PHP and Ajax help


cordoprod

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.