Skip to content Skip to sidebar Skip to footer

Need Help In Completing The Contact Form

I am making a contact form with the following code

Solution 1:

Your JS was not correct. You cannot use # in getElementById('#type') on native Javascript (I think you might be confused with jQuery)

Here is the correct code,

functionfindselected(){
    var state = document.getElementById('type');
    var notus = document.getElementById('model');
    var year = document.getElementById('year');
    var maker = document.getElementById('maker');
    notus.disabled = (state.value == "Automotive Service") ? false : true;
    year.disabled = (state.value == "Automotive Service") ? false : true;
    maker.disabled = (state.value == "Automotive Service") ?  false : true;
  }

Demo: http://jsfiddle.net/F2PLF/1/

Update: You may have to rewrite the if condition in your php code for $_POST['maker'], $_POST['model'] and $_POST['year'].When they are disabled, no value will be sent to server. so can either remove those from the if condition, like this

if(isset($_POST['fname']) && isset($_POST['phone']) && isset($_POST['e_mail']) && isset($_POST['service']) && isset($_POST['message'])){

Or you may have to re-write your if condition based on the selected values from the drop-down <select>

Solution 2:

When form elements are disabled they will not be sent, so they will not be available in $_POST. So this line -

if(isset($_POST['fname']) && isset($_POST['phone']) && isset($_POST['e_mail']) && isset($_POST['service']) && isset($_POST['maker']) && isset($_POST['model']) && isset($_POST['year']) && isset($_POST['message']))

will fail.

You can either use read-only, remove the disabled on submit, or change your if(isset())...

see - http://www.w3.org/TR/html401/interact/forms.html#h-17.12

Solution 3:

to get the empty values in $_POST[] array this post can help

try to use simple if loop in js

like:

functionfindselected(){

if(document.getElementById("type").value=="Automated Service")
    {
    notus.disabled = (state.value == "Automotive Service") ? false : true;
        year.disabled = (state.value == "Automotive Service") ? false : true;
        maker.disabled = (state.value == "Automotive Service") ?  false : true;
    }
}

Post a Comment for "Need Help In Completing The Contact Form"