Forum Moderators: open
For field validation I've been able to use "document.forms[x].elements[x].value" to accomplish my goal but I also wish to pre-fill field values with a name/value pair passed from the URL (mainly so I can create one form for many possible referring links rather than one each).
Here's the code (found in these fine forums) that I'm trying to make work with some of these funky field names:
<script>
function getIdFromQstring() {
var url = document.location+''; // Insures string
q=url.split('?');
if (q[1]) {
var pairs = q[1].split('&');
for (i=0;i<pairs.length;i++) {
var keyval = pairs[i].split('=');
if (keyval[0] == 'Field_name') { var v = keyval[1]; break; }
}
}
if (v) { return v; }
}
var Field_name = getIdFromQstring();
if (Field_name) { document.form_name.Field_name.value=Field_name; }
</script>
Just for simplicity I've used the field name as a variable name as well (follows the example I borrowed).
Can anyone think of a tricky way around these crazy field names?
Thanks!
Since it sounds like you cannot, your best bet is probably going to be to loop through document.form_name.elements, and test if document.form_name.elements[i].name == Field_name. Not quite as effecient, but it should work for you.