Hi
I'm having problem with some radiobuttons. On this page I have two groups of radiobuttons and four textboxes. The code works fine with the first set of radiobuttons, but when I try to add code for the second group it doesn't work.... Here's the code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Test</title>
<script type="text/javascript" language="javascript">
var http_request = false;
function makeRequest(url, parameters) {
http_request = false;
if (window.XMLHttpRequest) { // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
// set type accordingly to anticipated content type
//http_request.overrideMimeType('text/xml');
http_request.overrideMimeType('text/html');
}
} else if (window.ActiveXObject) { // IE
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
http_request.onreadystatechange = alertContents;
http_request.open('GET', url + parameters, true);
http_request.send(null);
}
function alertContents() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
//alert(http_request.responseText);
result = http_request.responseText;
document.getElementById('myspan').innerHTML = result;
} else {
alert('There was a problem with the request.');
}
}
}
function get(obj) {
var getstr = "?";
for (i=0; i<obj.childNodes.length; i++) {
if (obj.childNodes[i].tagName == "INPUT") {
if (obj.childNodes[i].name == "Name") {
getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
}
if (obj.childNodes[i].name == "Email") {
getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
}
if (obj.childNodes[i].name == "Script") {
if (obj.childNodes[i].checked) {
getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
}
if (obj.childNodes[i].name == "Annat") {
getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
}
if (obj.childNodes[i].name == "Annat2") {
getstr += obj.childNodes[i].name + "=" + obj.childNodes[i].value + "&";
}
}
}
}
makeRequest('get.php', getstr);
}
</script>
</head>
<body>
<h1>Ange namn och epost:</h1> <br />
<form action="javascript:get(document.getElementById('myform'));" name="myform" id="myform">
Namn: <input type="text" name="Name" value=""><br />
Epost: <input type="text" name="Email" value=""><br />
<h1>Rösta på följande:</h1>
<h2>Fråga 1: Vilket script språk gillar du bäst?</h2>
<input type="radio" name="Script" value="PHP" checked> PHP<br />
<input type="radio" name="Script" value="ASP.NET"> ASP.NET<br />
<input type="radio" name="Script" value="JSP"> JSP<br />
<input type="radio" name="Script" value="AJAX"> AJAX<br />
Annat: <br />
<input id="Annat" type="text" value="" />
<br />
<br />
<input type="radio" name="os" value="MS Windows" checked> MS Windows<br />
<input type="radio" name="os" value="LINUX" > LINUX<br />
<input id="Annat2" type="text" value="" /> <br />
<input type="button" name="button" value="Rösta!"
onclick="javascript:get(this.parentNode);">
</form>
<br><br>
Dina svar:<br>
<span name="myspan" id="myspan"></span>
</body>
</html>
And here's the php file.
<?php
foreach ($_GET as $key => $value) {
echo $key . ' : ' . $value . '<br />';
}
?>
I would very much appricate some help, since I have not found a solution for this despite hours of googleing...