|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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>
|
|
#3
|
|||
|
|||
|
second way of doing this doesn'twork in firefox. Is there any way I can make it work in firefox?
|
|
#4
|
||||
|
||||
|
What's the error you're getting in Firefox?
|
|
#5
|
|||
|
|||
|
Quote:
Source File: program's url Line: 86 |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > changing dynamically created form fields with js |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|