954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

getElementById

Hello,

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


Choose a type Report Test One Report Test Two Report Test Three 

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

AboJaD
Newbie Poster
7 posts since Jul 2007
Reputation Points: 10
Solved Threads: 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);
paulrajj
Junior Poster
101 posts since Mar 2010
Reputation Points: 17
Solved Threads: 37
 

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.

AboJaD
Newbie Poster
7 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 

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

paulrajj
Junior Poster
101 posts since Mar 2010
Reputation Points: 17
Solved Threads: 37
 

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.

AboJaD
Newbie Poster
7 posts since Jul 2007
Reputation Points: 10
Solved Threads: 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

Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

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

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

Airshow

Airshow
WiFi Lounge Lizard
Moderator
2,683 posts since Apr 2009
Reputation Points: 321
Solved Threads: 372
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: