Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    15
    Thanks
    3
    Thanked 0 Times in 0 Posts

    process elements returned getElementsByName

    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]

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    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?

  • #3
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    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
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • Users who have thanked A1ien51 for this post:

    javaguy1007 (03-24-2009)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •