Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

editing fieds using javascript?

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
hi,
i have an asp page with the following items that were created using a loop.
Code:
<tr>
   <td><INPUT type="text" NAME="itmnbr" size=10></td> 
   <td><INPUT type="text" NAME="qty" size=10></td>
   <td><INPUT type="text" NAME="itmprice" size=10></td> 
</tr> 
    
<tr>
   <td><INPUT type="text" NAME="itmnbr" size=10></td> 
   <td><INPUT type="text" NAME="qty" size=10></td>
   <td><INPUT type="text" NAME="itmprice" size=10></td> 
</tr> 
    
<tr>
   <td><INPUT type="text" NAME="itmnbr" size=10></td> 
   <td><INPUT type="text" NAME="qty" size=10></td>
   <td><INPUT type="text" NAME="itmprice" size=10></td>  
</tr>

<tr>
   <td><INPUT type="text" NAME="itmnbr" size=10></td> 
   <td><INPUT type="text" NAME="qty" size=10></td>
   <td><INPUT type="text" NAME="itmprice" size=10></td>  
</tr>
i want to use an existing javascript that calls different pages, to edit these fields (like non-zero price, non-blank item_nbr, non-zero qty, etc...)
how would i reference these fields, since they all have same names in this coding?
thanks for help.
 
On the same page, you can use document.getElementsByName() method.
On "different page", don't know what you mean. The principle is to reference to the window of the "page" (if through window.open, it is opener) and then followed again the same, such as opener.document.getElementsByName().
 
1st, you are going to run into problems if you intend to have a number of fields sharing the same name. [thumbsdown]

2nd, I advise you revise your ASP pages to address the 1st problem and possibly use a numeric sequence to make them unique.

3rd, when you open a window you give it a name, you can then reference it by that name and so you can reference all elements within the window. I think it will be something like

window.WINDOWNAME.FORMNAME.FIELDNAME.value

Not sure about this but just give it a try and see what happens.

4th, if you must keep the same name (and I would not understand why), try giving them unique IDs and use that.

Good luck!




--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
>1st, you are going to run into problems if you intend to have a number of fields sharing the same name.
I won't say it is fabulous, but a priori thumb down? I don't think so.
 
tsuji,
thanks for reply. on the different page, i use request.form
and all the items with same name show up as an array that are separated by comma. i can split them and use each one as a unique item. but on the same page, how do i reference itemnbr(1) as opposed to itemnbr(2)?
southbeach,
i think coding each and every field that's repeated, is a tedious job. i put the 4 items just for brevity. the actual code has 12 lines that repeat. i know this code is not very 21st century-ish, but i inherited it. i'm just trying to put some field edits in place.
 
tsuji,
when you say "use document.getElementsByName()",
how would i reference itemnbr(1) vs. itemnbr(2)?
do i construct a loop? i'm not sure what you mean.
thanks.
 
I thought that to reference them under an array you would have needed to include [] or () within the name. That said, if that is the case, then it makes sense to keep same name.

In the same token, if referencing them through an array, you will not be able to use getElementByName but the object itself. This requires you to look more into DOM.

--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
thanks,
when you say "This requires you to look more into DOM." can you give me an example of how i would construct a loop, by which it will check that all the values in ibmnbr is present?
thanks.
 
Sorry I could not ... The only case of DOM I've ever used is when I worked on a script to transfer values from one combo box to another.

I use PHP and so when facing this kind of thing, I normally use PHP + JS + XAJAX to get the job done. I simply fall into my comfort zone and work with it there.

I will do a little digging and post back if I find a suitable suggestion.


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
never mind.
i figured it out. here's how it's done:
Code:
    for (i=0;i<=3;i++)
       { 
        y = Form1.itmnbr[i].value;
        alert(y); 
       }
this loops through all the itmnbr field one at a time.
cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top