Pop up window details to update parent details

Dear Paul,
Correct me here. So what is next run a for loop is it?
Step 1.var form1= document.getElementById(‘form1’);
Step 2.var links = form1.getElementsByTagName(“a”);

It is.

Dear Paul,
Ok have now this. What to check next getValue is it?

function validateForm()
{
var form1= document.getElementById(‘form1’);
var links = form1.getElementsByTagName(“a”);
for (var i = 0; i < links.length; i++) {

alert("I : "+i);
}

Well if you’re lazy you can use innerHTML, but that’s more expensive in terms of processing time. You should be fine instead just checking the nodeValue of the element itself.

Dear Paul,
Must I do like this is it

for (var i = 0; i < links.length; i++) {

alert("I : "+i)i.firstChild.nodeValue);
}
?

You’re wanting to check if it’s equal to a certain value, aren’t you?

Dear Paul,
I am doing it like this but is not checking the value either.

var form1= document.getElementById(‘form1’);
var links = form1.getElementsByTagName(“a”);
for (var i = 0; i < links.length; i++) {

if(i.firstChild.nodeValue==“Select”)
{
alert(“Did not select value:”);
}
}

You are attempting to get the firstChild of i, which is a number. Can you see the problem there?

Dear Paul,
So what is the right method then? What does the first child reference to which number ?

The number should be used to retrieve one of the elements from the links array. It is from those elements that you can gain a reference to the firstChild

Dear Paul,
So what is the right method to get the value of the “a” itself then? Thank you.

Do you know how to use a for loop in order to loop through items of an array?

Dear Paul,
I am not too sure because from what I understand this is looping through all the “a” right? for (var i = 0; i < links.length; i++)? so what else array I need?

No, that is not looping through all of the “a”. What that does is to set the i variable to a number that starts at 0, and each time through the loop the number increases by one.

You are supposed to use that number to retrieve the appropriate item from the array, that item in your case will then be one of the anchor links that you are wanting to work with.

The following on JavaScript Array Basics might be of some help for you to further your understanding of them.

Dear Paul,
I know about the arrays. But what I do not know which is the array and what this array consists of and what value can I get from this array? Saw an example of this getElementsByTagName(“a”)[0].href’ so must I do something like this ?

var links = form1.getElementsByTagName("a");

The links variable is the array.

It consists of elements, HTML elements, which you can tell from the above code are anchor elements.

and what value can I get from this array?

The value or benefit that you can get from the array, is that it contains all of the links within the form, which allows you to easily process them.

Dear Paul,
When I run this after submitting the form it shows me the length is 0? Why ya?

function validateForm()
{
var form1= document.getElementById(‘form1’);
var links = form1.getElementsByTagName(“a”);
alert(“Length:”+links.length);
for (var i = 0; i < links.length; i++) {

alert(“Links :”+links[0]);

}

It’s either because there are no links in there, or that the the form variable is undefined. Please link to a test page that demonstrates the problem.

Dear Paul,
Here is the link Untitled Document. Just select a drop down list value and then press submit button. Thank you.

It looks like your HTML code is causing the problem.


<table> 
<form action="/tm/addAssign.php" method="post" name="form1" id=form1 onSubmit="return validateForm();"> 
<tr> 

The form tag is in an invalid location, so web browsers automatically close off the form.

You should be able to get away with it though by putting the entire table within the form.