...

View Full Version : process elements returned getElementsByName



javaguy1007
03-19-2009, 04:40 AM
Hi

I am new to AJAX. I am calling a Ajax function from jsp and I need to process elements returned by document.getElementsByName(),

getElementsByName returns 4 elements.

I did some thing like this , but it is not working please help me

function myfunction(id)
{

if(document.getElementsByName("myname").value!="")
{
xmlHttp=GetXmlHttpObject()
if(xmlHttp==null)
{
alert("Browser does not support HTTP Request");
return
}

var Id = document.getElementsByName("myname").value;

for (var i = 0, i<=4; i++) {
var url="myjsp.jsp"
url=url+"?Id="+Id

xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

}

}

Please help me
Thanks
[/FONT]

TinyScript
03-19-2009, 07:03 AM
shouldn't you loop right away? You're creating elements, right? And you want to get them by name, so you gotta name them.


what's the value of id in myfunction(id)
I didn't see you use it anywhere. You're sending an empty var.

Later on down there, you're creating Id and giving it a value but I didn't see any value assigned other than getobject. Can you explain how it's supposed to work. I'm learning and I've not used php nor ajax methods yet, but i'd love to learn.

I wish I had a way to do php. Does anyone know if there's a way to have an old laptop work as a server so i can practice php?

A1ien51
03-20-2009, 12:54 AM
You are using the same variable so you are overwriting the last call.

Use a JavaScript library and make your life easier with Ajax calls.

Eric



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum