JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 18th, 2005, 12:51 PM
camh camh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 4 camh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 41 sec
Reputation Power: 0
Thumbs down changing dynamically created form fields with js

I have a page, created by a perl script. It prints a bunch of form fields on to a page, some of which need to be incremented by a JS and then written back to the fields.

I have this code (which increments a set of letters):
Code:
                <script language=\"javascript\" type=\"text/javascript\">
                <!--
                function changeButton(FORM_VALUE, FIELD) {

                        var VALUE_ONE = FORM_VALUE.charCodeAt(0);
                        var VALUE_TWO = FORM_VALUE.charCodeAt(1);

                        VALUE_TWO++;
                        if (VALUE_TWO == 91) {
                                VALUE_TWO = 65;
                                VALUE_ONE++;
                                if (VALUE_ONE == 91) { VALUE_ONE = 65; }
                        }

                        VALUE_ONE = String.fromCharCode(VALUE_ONE);

                        VALUE_TWO = String.fromCharCode(VALUE_TWO);
                        alert(VALUE_ONE + VALUE_TWO);
                        document.main.elements[FIELD].value = VALUE_ONE + VALUE_TWO;

                }
                //-->
                </script>


At the end of the code I have "document.main.elements[FIELD].value = VALUE_ONE + VALUE_TWO;" (which doesn't work) the FIELD variable passed to this function is the name of the form field. Is there any way to make this work? It would be a pain to do it by field numbers because it is almost completely random how many fields come before it.

thanks!

Reply With Quote
  #2  
Old August 18th, 2005, 01:29 PM
camh camh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 4 camh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 41 sec
Reputation Power: 0
nevermind, fixed it by doing it this way instead:

Code:
                <script language=\"javascript\" type=\"text/javascript\">
                <!--
                function changeButton(FIELD) {
                        var VALUE_ONE = document.getElementById(FIELD).value.charCodeAt(0)  ;
                        var VALUE_TWO = document.getElementById(FIELD).value.charCodeAt(1)  ;

                        VALUE_TWO++;
                        if (VALUE_TWO == 91) {
                                VALUE_TWO = 65;
                                VALUE_ONE++;
                                if (VALUE_ONE == 91) { VALUE_ONE = 65; }
                        }

                        VALUE_ONE = String.fromCharCode(VALUE_ONE);
                        VALUE_TWO = String.fromCharCode(VALUE_TWO);
                        document.getElementById(FIELD).value = VALUE_ONE + VALUE_TWO;
                }
                //-->
                </script>

Reply With Quote
  #3  
Old August 18th, 2005, 01:39 PM
camh camh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 4 camh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 41 sec
Reputation Power: 0
second way of doing this doesn'twork in firefox. Is there any way I can make it work in firefox?

Reply With Quote
  #4  
Old August 18th, 2005, 03:24 PM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
What's the error you're getting in Firefox?

Reply With Quote
  #5  
Old August 18th, 2005, 04:56 PM
camh camh is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2005
Posts: 4 camh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 51 m 41 sec
Reputation Power: 0
Quote:
Originally Posted by MadCowDzz
What's the error you're getting in Firefox?
Error: document.getElementById(FIELD) has no properties
Source File: program's url
Line: 86

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > changing dynamically created form fields with js


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT