0

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 :)

Edited by Dani: Formatting fixed

3
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by Airshow
0

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);

Edited by paulrajj: n/a

0

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.

0

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

0

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.

0

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

0

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

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

Airshow

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.