Note that there are some explanatory texts on larger screens.

plurals
  1. POSelect tag value not being included in my Ajax script
    text
    copied!<p>I have an ajax script that sends data from a contact form to a php script but the problem is that I am not able to get the value from the "select" tag. I am limited in my knowledge of javascript/ajax so please excuse any inappropriate descriptions or phrases as I really can only explain it how I know it. </p> <p><strong>HTML :</strong></p> <pre><code>&lt;form action="" method="POST" id="contact"&gt; &lt;table&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;First Name: &lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Last Name: &lt;/td&gt; &lt;td&gt;&lt;h2&gt;Email Address: &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" name="first_name"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="last_name"&gt;&lt;/td&gt; &lt;td&gt;&lt;input type="text" name="email"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;Street Address:&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;What's Dirty?&lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;input type="text" name="address"&gt;&lt;/td&gt; &lt;td&gt; &lt;select name="job" form="contact"&gt; &lt;option value="house"&gt;House&lt;/option&gt; &lt;option value="roof"&gt;Roof&lt;/option&gt; &lt;option value="garage-shed"&gt;Garage/shed&lt;/option&gt; &lt;option value="other"&gt;Other&lt;/option&gt; &lt;/select&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;Message: &lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;textarea name="message" cols="80" rows="5"&gt;&lt;/textarea&gt; &lt;input type="submit" id="submit" name="send" value="Send!" class="send-button"&gt; &lt;/form&gt; </code></pre> <p><strong>Ajax</strong></p> <pre><code> &lt;script type="text/javascript"&gt; $("#submit").click(function(e) { e.preventDefault(); var data_string = $("form#contact").serializeArray(); $.ajax({ type: "POST", url: "database.php", data: data_string, success: function(){ } }); return false; }); &lt;/script&gt; </code></pre> <p><strong>PHP</strong></p> <pre><code> print_r($_POST); $fname = $_POST['first_name']; $lname = $_POST['last_name']; $email = $_POST['email']; $address = $_POST['address']; $job = $_POST['job']; $message = $_POST['message']; </code></pre> <p>What I get from the script is this </p> <pre><code>[first_name] =&gt; John [last_name] =&gt; Smith [email] =&gt; j.smith@example.com [address] =&gt; 1234 Jamestown Rd. </code></pre> <p>Please keep in mind I am very new to this so a simple mistake really isn't all that obvious to me. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload