Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-03-2004, 09:32 PM
WebProWorld Member
 

Join Date: Jul 2004
Location: 03301
Posts: 29
elso RepRank 0
Default Looking for alternative to getElementById

Hello

I am trying to find an alternative for JS to locate a page element.

Here is a simple test form I am experimenting with:
Code:
<form name="form1" method="post" action="">
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><input name="image1" type="text" id="image1" size="30"></td>
            </tr>
          </table>
          </form>
Now in simple JS the field named "image1" can be located or mapped with:
Code:
document.form1.image1.value=...
Ok, now let's assume I need 2 identically named fields in this form like so:
Code:
<form name="form1" method="post" action="">
          <table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td><input name="image1" type="text" id="image1" size="30"></td>
            </tr>
            <tr>
              <td><input name="image1" type="text" id="image1a" size="30"></td>
            </tr>
          </table>
          </form>
Is there anyway to name the <TD> tags identify a different path to each? I know I can use the "getElementById" to do this, bet it seems that older browsers don't recognize this. Any other solutions? Any html tags I can use that can be "named"?

Thanks
nelson
Reply With Quote
  #2 (permalink)  
Old 09-04-2004, 09:44 PM
WebProWorld Pro
 

Join Date: May 2004
Location: United Kingdom
Posts: 176
php~pro RepRank 0
Default

You would have to give details about how you are processing the form and whats its purpose. Email or db function. You can dyanamically write out a form but its scripting would depend on the server technology you have with your hosting.

For example you could write elemnts as

Code:
<?php for($i = 1; $i <= 2; $i++){ ?>

<TR>
  <TD><input name="image" type="text" id="image"[<?php echo "$i";?>] size="30"></TD>
</TR>

<?php } ?>
This would output 2 rows as shown below.

Code:
<TR>
  <TD><input name="image" type="text" id="image1" size="30"></TD>
</TR>
<TR>
  <TD><input name="image" type="text" id="image2" size="30"></TD>
</TR>
Post more details about what you aim to achieve so user can help you further.
Reply With Quote
  #3 (permalink)  
Old 09-04-2004, 11:39 PM
WebProWorld Member
 

Join Date: Jul 2004
Location: 03301
Posts: 29
elso RepRank 0
Default Clarified

Hello

I re-read my question and can see how it could have been misinterpreted. Sorry, I am not looking for alternative to the JS, but rather an alternative method for the JS to write to these fields having the same name. I used the getElementById for the JS to find the appropriate field to write to, but it seems that getElementById is not recognized by older browsers. In short, I custom print t-shirts and stuff like that. Variables involved with pricing and ordering include the number of shirts, the number of prints per shirt and the size of each print. To do this, I entered the prints as separate products, thus they each carry their own price and their own quantity price breaks. So each of these print items would need to carry their own quantity fields (hidden) and when the customer enters a quantity it gets copied to all the other quantity hidden fields.

So I am only looking for an alternative to the getElementById to locate all the quantity fields (which all carry the name "quantity" and can't change that) they are all in the same form.

Thanks
Nelson

If you want to see a sample of this page, please see any of the product pages at
Code:
www.elsographics.com
.
Reply With Quote
  #4 (permalink)  
Old 09-05-2004, 07:19 AM
WebProWorld Pro
 

Join Date: May 2004
Location: United Kingdom
Posts: 176
php~pro RepRank 0
Default

Use a loop to increnet names. See one suggestion in your other post.
Reply With Quote
  #5 (permalink)  
Old 09-05-2004, 11:36 AM
WebProWorld Pro
 

Join Date: May 2004
Location: United Kingdom
Posts: 176
php~pro RepRank 0
Default

The below should work fine. This code was passed to me about 6 months ago. I have no ideas as to the original author, but wasnt me.

var getElementWithId;
if(document.getElementById){

getElementWithId = function(id){
return document.getElementById(id);
}
}else if(document.all){

getElementWithId = function(id){
return document.all[id];
}
}else{

getElementWithId = function(id){
return null;
}
}
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0