1

I didn't get any more responses after the previous question I had. I got a ton of help from the last question, thanks to all. How I'm doing this is, based on the selection "Concerning" it will pull a mirrored index value(email address) from an array and replace the "recipient" value with it. There are a few selections that will pull the same email address. Here is the last issue I'm having - The test page with this java script with "email#1, email#2,...." worked on a test page from mtsherman(thanks a bunch!). When I add the actual emails into this array, it won't pull the value over to the recipient value. It's probably a very simple fix, but I'm novice and stumped! Thanks in advance.

<html>
<head>
<script language="JavaScript">
document.getElementById('Concerning').onchange = function() { 
    var myArray = ["Empty", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]", 
                   "[email protected]",
           "[email protected]",
           "[email protected]",
           "[email protected]"];

    document.getElementsByName('recipient')[0].value = myArray[this.selectedIndex];
};
</script>
</head>
<body>
<form action="/cgi-bin/formmail" method="post">
<select id="Concerning">
                    <option value="Choose One">Choose One
            <option value="Benefits">Benefits
            <option value="Customer_Service">Customer Service
            <option value="Employee_Paperwork">Employee Paperwork
            <option value="Human_Resources"> Human Resources
            <option value="Open_Positions">Open Positions
            <option value="Payroll">Payroll
            <option value="Quote_Request">Quote Request
            <option value="Safety">Safety
            <option value="Technical_Support">Technical Support
            <option value="Training">Training
            <option value="Unemployment">Unemployment
            <option value="Workers_Compensation">Workers' Compensation
    </select>
<input TYPE="hidden" NAME="recipient" VALUE="">
    <input TYPE="hidden" NAME="subject" VALUE="Contact Form">
    <input TYPE="hidden" NAME="email" VALUE="[email protected]">
    <input TYPE="hidden" NAME="required" VALUE="Name,Phone,Email,Concerning,Comments">
</form>
</body>
</html>

1 Answer 1

1

Your code is running before the page has loaded. You should see an error in your JavaScript console complaining that document.getElementById('Concerning') is null. Use an onload handler to delay execution of your code until the page is ready:

window.onload = function () {
    document.getElementById('Concerning').onchange = function () {
        ...
    };
};
Sign up to request clarification or add additional context in comments.

5 Comments

Worked like a charm! Now their is no "Concerning" value, I have another script checking for required fields and it shows blank. Any ideas?
@kswizzle33 - That sounds like a separate question. Post as many questions as you like. Make sure each question is reasonably specific. And especially make sure to upvote every helpful answer. Then, of the helpful answers, please also accept the best answer.
Ok, I can't voteup until 15 rep but i'll make sure to do so when I can. NEW Question. I'm able to send out the email, but now there is no "Concerning" value. So since it's a required field, the php script will tell me that there is no value for Concerning. Anyway to give it the value selected originally?
@Kswizzle33 - Your php is not getting the value for Concerning because it is not being submitted. A form element must have a name attribute in order for it to be included in the form submission. Add name="Concerning" to your <select> and it should work.
I'm a have to say, your not too bad gilly3! All jokes aside you helped me complete this form and I really appreciate it. I dubbed this as a useful answer and the answer to my question, thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.