Hi, I've started today trying to get a hold on AJAX. Im starting with basics.
I've created a page, where there are two input fields, + two radio buttons. The radio buttons is labled "ja" and "Nei" (Norwegian for yes and no). Default the radio button labled "nei" is checked. The purpose of the yes and no buttons is whether or not the above inputfield labled "orgnr" is to be displayed.

I tweked my own (yeah, right... i've followed an example an tweaked it) script, so it works rather fine now. But i've split it into two scripts. One for Yes and one for No. So, this can't be the easiest way to to it.

I've got these files:
- ny_bedrift.php
- orgnr_JA.js
- orgnr_NEI.js
- orgnr_JA.php
- orgnr_NEI.php

-----------------------------------------------------------------------------------------------
ny_bedrift.php (holding the form and inputs)
-----------------------------------------------------------------------------------------------
<form action="" method="post">
<table width="230" border="0">
<tr>
<td colspan="2"><b>Ny bedrift</b></td>
</tr>
<tr>
<td width="90">Navn:</td>
<td width="171"><input name="bed_navn" type="text" id="bed_navn" size="40" /></td>
</tr>
<tr id= "orgnr_form">
<td>Org.nr:</td>
<td><input name="orgnr" type="text" id="orgnr" size="40" maxlength="9" /></td>
</tr>
<tr>
<td colspan="2">Registrer uten org.nr: Ja
<input name="orgnrsprml" type="radio" id="orgnr_form_ja" value="0" onchange="hentOrgFeltJA(this.value)" />
Nei <input name="orgnrsprml" type="radio" id="orgnr_nei" value="1" checked="checked" onchange="hentOrgFeltNEI(this.value)"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Registrer [Neste]" /></td>
</tr>
</table>
<input type="hidden" value="1" name="form_state" />
</form>';

-----------------------------------------------------------------------------------------------
orgnr_JA.js (holds the javascript for getting the text if yes is choosen
-----------------------------------------------------------------------------------------------

var xmlHttp;

function hentOrgFeltJA(str){
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Nettleseren din støtter ikke http forespørsler");
return
}
var url="ad_domain/act/orgnr_JA.php";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged ;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
document.getElementById("orgnr_form").innerHTML=xmlHttp.responseText;

}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
-----------------------------------------------------------------------------------------------
orgnr_JA.php (generates the text to be displayed
-----------------------------------------------------------------------------------------------
<?php

$orgnr_reg = $_GET["q"];

if($org_nr_reg==0){
echo '<td>&nbsp;</td><td>&nbsp;</td>';

}
?>
------------------------------------------------------------------------------------------------

orgnr_NEI.js and orgnr_NEI.php is identical to orgnr_JA.js and orgnr_JA.php
exept url points in js points to NEI.php, and NEI.php holds a different text.

Any good solutions to this? would help alot.