...

View Full Version : need help with js code. want to assign a variable two values one by one....



Peeyush
05-16-2012, 04:05 PM
EDIT: goto post #7

here goes JS code:
(keep an eye on codes of type: document.getElementById('footerX').innerHTML=X;)


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:


<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....

Peeyush
05-16-2012, 04:18 PM
anyone?

Peeyush
05-16-2012, 04:43 PM
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...

Philip M
05-16-2012, 04:57 PM
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.

Old Pedant
05-16-2012, 08:05 PM
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

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.

Peeyush
05-17-2012, 06:14 AM
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

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:



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" ;
}

Peeyush
05-17-2012, 06:34 AM
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. :)

Peeyush
05-17-2012, 07:08 AM
Okay guys Good News! i think i spotted the error!

in the loop


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....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum