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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts

    need help with js code. want to assign a variable two values one by one....

    EDIT: goto post #7

    here goes JS code:
    (keep an eye on codes of type: document.getElementById('footerX').innerHTML=X
    Code:
    function details()
    {
    	var choo = document.getElementById("choo");
    	aa = choo.chooserver.value;
    	bb = choo.chooversion.value;
    	if(aa==1) {k=0}
    	else if(aa==2) {k=1}
    	else {k=false}
    	pa= domain[k].getElementsByTagName("server") ;
    	pb="";
    	pc = domain[k].getElementsByTagName("version");
    	pd= domain[k].getElementsByTagName("date");
    	pe= domain[k].getElementsByTagName("month");
    	pf= domain[k].getElementsByTagName("year");
    	
    	ta = (bb==1)? " T4 ":(bb==2)? " T3.6 " :(bb==3)? " T2.5 " : 100 ;
    	versions(ta);
    	document.getElementById('footer1').innerHTML='one';
    }
    function versions()
    {
    				for (i=0;i<=pc.length;i++)
    	  		{
    				a = pc[i].childNodes[0].nodeValue;
    				b = pa[i].childNodes[0].nodeValue;
    				comparedate(d,g,f);
    				dates(i, a);
    				document.getElementById('footer2').innerHTML='two';
    				if (a==ta)
    					{
    						addto()										
    						document.getElementById("mc"+i).innerHTML= txt ;
    						document.getElementById("md"+i).innerHTML= txt2 ; 
    					}
    				document.getElementById('footer3').innerHTML='tee';
    			}
    			document.getElementById('footer4').innerHTML='fou';
    }
    HTML:
    Code:
    <div id = "conten2">
    <table id="tb1" border="1px">
    </table> 
    </div> 
    <div id = "footer"> feet </div>
    <div id = "footer1"> feet1 </div>
    <div id = "footer2"> feet2 </div>
    <div id = "footer3"> feet3 </div>
    <div id = "footer4"> feet4 </div>
    <div id = "footer5"> feet5 </div>
    Desired Output:
    feet
    one
    two
    tee
    fou
    feet5
    Output:
    feet
    feet1
    two
    tee
    feet4
    feet5

    Area of error predicted:

    inside the for loop, the statement immediately after loop is not executed once loop ends, nor does it return to original function for execution of other statements which were written after the function containing the loop was called....
    Last edited by Peeyush; 05-17-2012 at 09:15 AM.

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    anyone?

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Philip M View Post
    Peeyush - this forum is not Twitter! Please have a look at forum guideline 5. It's ok to occasionally bump a thread, but only when done after an ample amount of time (ie: 2-3 days) have passed without a response, and never more than once. You have bumped your thread after only a few minutes - we are not standing around here 24/7 to answer your questions.
    Sorry to any and every member of this community who got affected by my this kind of behaviour. i shall not repeat it in future...
    Last edited by Peeyush; 05-17-2012 at 06:39 AM. Reason: Sorry

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Peeyush - this forum is not Twitter! Please have a look at forum guideline 5. It's ok to occasionally bump a thread, but only when done after an ample amount of time (ie: 2-3 days) have passed without a response, and never more than once. You have bumped your thread after only a few minutes - we are not standing around here 24/7 to answer your questions.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Nobody could possibly help you debug that code with what you showed.

    Just for *ONE* example (and there are many many more), you are doing
    Code:
    document.getElementById("mc"+i).innerHTML= txt ;
    but there are no elements with and ID of "mc0", let alone "mc1", "mc2", etc., anywhere in the HTML you show.

    If you expect help, you have to show *REAL* code. Not just part of your code.

    The best way to do this is to give us a LIVE URL to look at.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by Old Pedant View Post
    Nobody could possibly help you debug that code with what you showed.

    Just for *ONE* example (and there are many many more), you are doing
    Code:
    document.getElementById("mc"+i).innerHTML= txt ;
    but there are no elements with and ID of "mc0", let alone "mc1", "mc2", etc., anywhere in the HTML you show.

    If you expect help, you have to show *REAL* code. Not just part of your code.

    The best way to do this is to give us a LIVE URL to look at.
    Sorry, i forgot to add the function addto() which was called by one of the functions.... here it is:

    Code:
    function addto()
    {
    	txt = b ;
    	ma = document.getElementById("tb1");
    	mb = ma.insertRow(-1);
    	mc = mb.insertCell(0);
    	md = mb.insertCell(1);
    	mb.id = "mb" + i;
    	mc.id = 'mc' +i ;
    	md.id = 'md' + i ;
    	mc.innerHTML = "New";
    	md.innerHTML = "New2" ;
    }

  • #7
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Here is the live url of JS code: http://peeyush.tk/travian.js
    and here you can see it in action: http://peeyush.tk/travian.html

    (I would suggest that if you want to read the code, copy paste it into dreamweaver or some syntax highlighting software, there are many lines which i have hidden with //(line comment) for debugging purposes. as now you have urls, i will tell you what basically i am trying to do...

    When you goto http://peeyush.tk/travian.html , you will see two drop down lists and a submit button. if you select option 2 or 3 from first list and any other option from second list, the code works. if you want to see the xml file, you can at : http://peeyush.tk/travian.xml...

    in JS code, i have written - domain[k]. when you select option '.com.au' which is second option in first line, it sets k = 0, when you select third option, which is '.com', it sets k= 1, which means each time it goes through specific node searching for specific childnodes. now this is just a basic piece of code, later on i will be adding more than 50 checkboxes instead of drop down list in place of first list, so all i want is that my code runs number of times the check boxes selected, with value of k as the values of selected checkboxes i know its a bit complicated. hope the reader has understood.
    Last edited by Peeyush; 05-17-2012 at 09:16 AM. Reason: splleing

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Posts
    104
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Okay guys Good News! i think i spotted the error!

    in the loop
    Code:
    	for (i=0;i<=pc.length;i++)
    		{
    			a = pc[i].childNodes[0].nodeValue;
    			b = pa[i].childNodes[0].nodeValue;
    			comparedate(d,g,f);
    			dates(i, a);
    			document.getElementById('footer2').innerHTML='two';
    			if (a==ta)
    				{
    					addto()										
    					document.getElementById("mc"+i).innerHTML= txt ;
    					document.getElementById("md"+i).innerHTML= txt2 ; 
    				}
    			document.getElementById('footer3').innerHTML='tee';
    		}
    		document.getElementById('footer4').innerHTML='fou';
    if i replace (i=0;i<=pc.length-1;i++) with (i=0;i<=pc.length-1;i++)(added a -1) or simply for (i=0;i<pc.length;i++)( changed <= to <) it works! but i am still struck on what i originally wanted to do, which i explained in the previous post....


  •  

    Posting Permissions

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