Forum Moderators: open
I'm trying to set the value of a field in a form that has a space character in the name.
I'm trying to do something like this:
Code:
document.forms["otherform"].phone.value=document.forms["survey"].yourphone.value;
The problem is that 'phone' is actually supposed to be 'custom Phone'. When I try that, it doesn't work, though. The reason why I have to have a space in the name is because the form element is tied to our mass email distribution system (Aweber) and this particular element was created with a space, and cannot be changed.
So I'm thinking that hopefully there is a special character I'm supposed to use besides the space character to set the value? Unfortunately, I'm stumped.
Anyone have any ideas?
Thanks!
*j
<input type="text" name="Your Phone" id="other-phone">
........
<input type="text" name="Your Phone" id="survey-phone">
document.getElementById('other-phone').value=document.getElementById('survey-phone').value;
If you absolutely can't access the form fields, you could do some workarounds, for example, iteration through the form element's index in the source:
document.forms["otherform"].elements[3].value=document.forms["survey"].elements[6].value;
This gets to be a nightmare to maintain if the form fields move around at all.
the page I'm working with was created by using a program called 'Psychic Sales Letter'.
The page asks a series of questions in a survey format and has a form at the bottom (name, email, phone). When the button is clicked, it triggers an onClick event(it does not do a form submit. If that was the case, I don't think this would be an issue).
there is an aweber form that looks like this:
<form method="post" name="otherform" target="otherformsubmit" action="http://www.aweber.com/scripts/addlead.pl">
<input name="name" type="hidden">
<input name="from" type="hidden">
<input name="phone" type="hidden">
<input type="hidden" name="custom Phone" id="custom Phone">
<input type="hidden" name="meta_web_form_id" value="1683544204">
<input type="hidden" name="meta_split_id" value="">
<input type="hidden" name="unit" value="test">
<input type="hidden" name="redirect" value="http://www.myDomain.com/signup/thank-you.html">
<input type="hidden" name="meta_redirect_onlist" value="">
<input type="hidden" name="meta_adtracking" value="">
<input type="hidden" name="meta_message" value="1">
<input type="hidden" name="meta_required" value="from,name,phone">
<input type="hidden" name="meta_forward_vars" value="0">
</form>
there is some javascript code that takes values from the initial form and passes them to the aweber form:
document.forms["otherform"].name.value=document.forms["survey"].yourname.value;
document.forms["otherform"].from.value=document.forms["survey"].youremail.value;
document.forms["otherform"].phone.value=document.forms["survey"].yourphone.value;
Then, the aweber form is submitted:
document.forms["otherform"].submit();
When I try and do anything to the code that passes the phone value between forms, none of the data is submitted at all. If i leave it as-is, it's fine. I was able to confirm that I can hardcode a value for phone within the aweber form, and it still gets passed.
I'm not sure what the problem is, but it's definitely very odd...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled</title>
</head>
<body onload="loiloi()">
<form name="foo">
<input name="bar" value="bar">
<input name="baz bork" value="baz bork">
</form>
<script type="text/javascript">
function loiloi() {
alert(document.forms['foo'].bar.value);
document.forms['foo'].bar.value = "meh";
alert(document.forms['foo'].bar.value);
alert(document.forms['foo']['baz bork'].value);
document.forms['foo']['baz bork'].value = "mih moh";
alert(document.forms['foo']['baz bork'].value);
}
</script>
</body>
</html>
You should be able to access/modify the element and its value as needed.
[edited by: DrDoc at 11:11 pm (utc) on Aug. 14, 2008]