Hello,

I am trying to get the element of an option, but seems my code is not working:

<script type="text/javascript">
/*<![CDATA[*/
function reportsendipp()
{
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    ;
    }
  }
xmlhttp.open("GET","report_member.php?report=" + document.getElementById("ipps").value + "&&member=" + document.getElementById("track").value, true);
xmlhttp.send();
}
/*]]>*/
</script>

            <form style="display: none" id="ipp" action="">
            <select id="ipps" name="report_ipp">
            <option value="-1">Choose a type</option>
            <option value="1">&nbsp;Report Test One</option>
            <option value="2">&nbsp;Report Test Two</option>
            <option value="3">&nbsp;Report Test Three</option>
            </select>
            <input onclick="reportsendipp()" type="button" value="Report" />&nbsp;<input onclick="cancelreportipp()" type="button" value="Cancel" />
            </form>

<div><input style="display: none" id="track" value="15" /></div>

What i need to do is, when i choose let's say option number 2, string be sent as reported_member.php?report=2&&member=15

Any help is appreciated.

Thank you in advance :)

Recommended Answers

All 6 Replies

Hi,

I dont know why you are making the form to display none. And if u make the form to display block, i am sure the script will work without any problem.
if it does not let us know which browser you are using to accomplish this.

make small change of your code as below and make sure you are displaying block of the form tag and check.

<form style="display: block" id="ipp" action="">
var url = "report_member.php?report=" + document.getElementById("ipps").value + "&&member=" + document.getElementById("track").value;
alert(url);
xmlhttp.open("GET",url, true);

Hello,

Thank you for the reply, i am displaying none, because i don't want the form to show on the web page, but it does change to block once a radio button is chosen.

I have changed the form display to block, but still nothing happens when i click on the button Report.

I am trying the code on IE8,FF,Chrome it doesn't work on any of them.

I believe the issue could be in the document.getElementById("ipps").value, maybe it should be document.getElementById("ipps").somethingElse.value (know what i mean).

Any help is appreciated.

Thank you in advance.

Hi,
Could you post the full code here. It might be helpful to know the cause of the problem.

Hello,

Problem solved, thanks guys.

The problem was using "xmlhttp.open", since i don't need it to send back any echo to same page i just used window.location instead.

Thanks for your help.

AbsJaD,

Try this:

function reportsendipp() {
	var ippsEl   = document.getElementById('ipps');
	var memberEl = document.getElementById('track');
	var ippsVal   = (!ippsEl)   ? null : Number(ippsEl[ippsEl.selectedIndex].value);
	var memberVal = (!memberEl) ? null : Number(memberEl.value);
	if(!ippsVal || ippsVal===-1) {
		alert('First, choose a type');
		return false;
	}
	if(!memberVal || isNaN(memberVal) ) {
		alert('Member/track value must be a number');
		return false;
	}
	if (window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); }
	else { xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); }
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState==4) {
			if (xmlhttp.status==200) { alert(xmlhttp.responseText); }
			else { alert('Report process has failed'); }
		}
	}
	searchStr = [];
	searchStr.push('report=' + ippsVal);
	searchStr.push('member=' + memberVal);
	xmlhttp.open('GET','report_member.php?'+searchStr.join('&'), true);
	xmlhttp.send();
	return false;
}

Includes a bit of light validation.

Airshow

Whoops, just saw your "solved" message after posting.

Maybe you would still like to consider using the validation/alerts.

Airshow

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.