1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

getElementById help

Discussion in 'JavaScript' started by lost, Nov 24, 2005.

  1. #1
    if i have the following line of code, could i somehow get the value of each textfield by assigning it to an array???

    
      function submitSave()
      {
         var iarray  = new Array();
    
         for (i=0; i<numItems; i++)
         {
             document.getElementById("textfields").value = iarray;         
         }
      }
    
    Code (markup):

     
    lost, Nov 24, 2005 IP
  2. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #2
    What this will do is it will convert the content of the array to a comma-delimited list of values (which will be empty in this case 'cause you just created an array) and assign it to the text field.

    Simply put, this assignment will reset the content of "textfields" to a zero-length string.

    J.D.
     
    J.D., Nov 24, 2005 IP
  3. cyclinder

    cyclinder Peon

    Messages:
    29
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    var iarray = "value1_value2_value3".split('_');

    for (i=0; i<iarray.length; i++)
    {
    document.getElementById("textfields").value = iarray;
    }
     
    cyclinder, Nov 25, 2005 IP
  4. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #4
    If you want to get the values from the FORM into the ARRAY, then you need something like:

    for (i=0; i<numItems; i++)
    {
    iarray=document.getElementById("textfields" + i).value;
    }

    Something like this, anyway..
     
    BurgerKing, Nov 25, 2005 IP
  5. mikmik

    mikmik Guest

    Messages:
    356
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You have a div you want to write to. Make it : <div id="holder"></div>.Then -
    document.getElementById("holder").innerHTML = blah

    You cannot get info from submit into javascript. You must post, or alternately, get, with the submit call from your input text form (on submit="file.php" action="post/get").

    Lets say you make a httprequest for "doc.xml", either in the 'onload' function, or with an evewnt caller:
    function sendRequest(doc){
    // check for existing requests
    if(xmlobj!=null&&xmlobj.readyState!=0&&xmlobj.readyState!=4){
    xmlobj.abort();
    }
    try{
    // instantiate object for Mozilla, Nestcape, etc.
    xmlobj=new XMLHttpRequest();
    }
    catch(e){
    try{
    // instantiate object for Internet Explorer
    xmlobj=new ActiveXObject('Microsoft.XMLHTTP');
    }
    catch(e){
    // Ajax is not supported by the browser
    xmlobj=null;
    return false;
    }
    }
    // assign state handler
    xmlobj.onreadystatechange=stateChecker;
    // open socket connection
    xmlobj.open('GET',doc.xml,true);
    // send GET request
    xmlobj.send(null);
    }

    Then, you check for a return:

    function stateChecker(){
    // if request is completed
    if(xmlobj.readyState==4){
    // if status == 200 display text file
    if(xmlobj.status==200){
    // create data container
    createDataContainer();
    // read XML data
    data=xmlobj.responseXML.getElementsByTagName('message');
    // display XML data
    displayData();
    }
    else{
    alert('Failed to get response :'+
    xmlobj.statusText);
    }
    }
    }

    in which you have : <div id="container"></div>, and you :
    document.write.getElementById.innerHtml.

    eg:

    function createDataContainer(){
    var div=document.getElementById('container');
    if(div){return};
    var div=document.createElement('div');
    div.setAttribute('id','container');
    document.getElementsByTagName('body')[0].appendChild(div);
    }

    If you: var item = new item
    item = getElementById.innerHtml() {...
    Okay, I am way past bedtime. Here is better explanation:
    yeah, I wish I new this, LMAO:


    Oh boy:


    You don't have to create text links, this ias just an example I copied from DevShed: JavaScript Remote Scripting: Processing XML Files

    You can assign anything as a var, then use it however, of course.
    From above:


    You can read this guy, he is the best one of many I have read, more advanced, but very clear:
    Alejandro Gervasio

    THIS: JavaScript Remote Scripting: Fetching Server Data with the DOM

    Basically, what I have been doing, is getting individual sets and assigning them by each as they come:
    document.getElementById("id_name").innerHTML(){
    if(is==good){
    blah;
    }
    else(is_not_good){
    other blah;
    }}

    document.write=nextRoundIsOnMe.getWalletByLocation ;o)))
     
    mikmik, Nov 26, 2005 IP
  6. mikmik

    mikmik Guest

    Messages:
    356
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Basically, what BurgerKing said
     
    mikmik, Nov 26, 2005 IP
  7. mikmik

    mikmik Guest

    Messages:
    356
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Here, I grab a ton of stuff, all from one xml file, and assign it to three different places(marker points, sidebar, hidden div[info window]):
    [i]

    [url]http://mikx2.com/mikmap/wowza.php[/url]

    From an xml file: [QUOTE] <?xml version="1.0" ?>
    - <markers>
    <marker lat="27.99381657128786" lng="86.82481689453125" location="Webfuscious" img="../pics/250px-Mt_Everest_aerial_2005.jpg" link1="Top of the World" url1="http://www.everestnews.com/" address="6000 Ft. Base, Mt Everest" groupid="Asia,Australia" />
    <marker lat="27.99381657128786" lng="86.82481689453125" location="Webfuscious" img="../pics/250px-Mt_Everest_aerial_2005.jpg" link1="Top of the World" url1="http://www.everestnews.com/" address="6000 Ft. Base, Mt Everest" groupid="Asia,Australia" />
    <marker lat="49.8862016713458" lng="-119.48206901550293" location="mikmik" link1="Mikx2" url1="http://mikx2.com/" link2="Factor1" url2="http://factor1.net/" address="Kelowna" groupid="Canada,Australia" />
    <marker lat="47.5189252" lng="-100.88691473" location="rocky" img="../pics/rocky1.jpg" img_height="75" link1="North Dakota Fishing" url1="http://www.rtfi.us/" address="Turtle Lake" groupid="UnitedStates" />
    <marker lat="44.9327" lng="-75.613" location="minstrel" link1="PsychLinks Online" url1="http://forum.psychlinks.ca/" link2="Written Voice" url2="http://www.writtenvoice.com/" address="Oxford Mills" groupid="Canada" />
    <marker lat="28.5435" lng="-81.3963" location="Steven" link1="Ogre Hosting" url1="http://www.ogrehosting.com/" link2="Cold Fusion Programming" url2="http://www.veradicetechnologies.com/" address="Orlando, Florida" groupid="UnitedStates" />
    <marker lat="26.7189" lng="-80.1248" location="Daren" link1="Web Page Turner" url1="http://www.webpageturner.com/" address="West Palm Beach, Florida" groupid="UnitedStates" />
    <marker lat="51.590723" lng="-0.131836" location="Centaur" img="../pics/erimusLogo.gif" img_height="77" link1="Erimus Web Desaign" url1="http://www.erimus.com/" link2="SVG Software Solutions" url2="http://www.inbay.co.uk/" address="London, England" groupid="Europe" />
    </markers>
    [/QUOTE][/i]
     
    mikmik, Nov 26, 2005 IP
  8. lost

    lost Peon

    Messages:
    144
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Thanks guys for all your help.
    I've got this code so far, however, it seems like nothing is getting returned in the array. The alert keeps returning undefined...can someone please help me.

    
      function submitSave()
      {
         var iarray  = new Array();
    
         for (i=0; i<numItems; i++) 
         { 
             iarray[i] = document.getElementById("textfields").value;  
             alert(iarray[i]);
         } 
      }
    
    Code (markup):
     
    lost, Nov 28, 2005 IP
  9. BurgerKing

    BurgerKing Active Member

    Messages:
    397
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    58
    #9
    Hi,

    The code you are using assumes that all the fields you want to read are called

    textfields0
    textfields1
    textfields2
    textfields3

    etc. If your fields are called txtFirstName, txtLastName, txtAddress etc - then this will not work.

    Also, the code assumes you have a global variable called numItems, and that it is set to something higher than 0.

    Hope this helps. How about posting a more complete example?
     
    BurgerKing, Dec 5, 2005 IP