現在、フォームは正しい情報を送信していますが、状態がありません。Ajax 成功関数を使用しています。唯一のことは、値が固定されたものではなく、選択された状態に依存することです。どうすればそれについて行くことができますか?
JS:
$('#sendFormBtn').live('click', function(){
formdata = $('#submitForm').serialize();
$.ajax({
type: 'POST',
url: 'includes/contactForm.php',
data: formdata,
success: function(){
$('input[name=name]').val('Name');
$('input[name=email]').val('Email');
$('input[name=address]').val('Address');
$('input[name=state]').val('');
$('input[name=city]').val('City');
$('input[name=zip]').val('Zip Code');
$('textarea[name=message]').val('Leave a message');
}
});
});
HTML:
<form id="submitForm">
<table cellpadding="1" cellspacing="1">
<tr>
<td width="223">
<input type="text" size="35" name="fullname" value="Full Name" onFocus="if(this.value == 'Full Name') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Full Name';}" />
<br />
</td>
</tr>
<tr>
<td>
<input type="text" size="35" name="youremail" value="Your Email" onFocus="if(this.value == 'Your Email') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Your Email';}" />
<br />
</td>
</tr>
<tr>
<td>
<input type="text" size="35" name="address" value="Address" onFocus="if(this.value == 'Address') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Address';}" />
<br />
</td>
</tr>
<tr>
<td>
<input type="text" size="35" name="city" value="City" onFocus="if(this.value == 'City') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'City';}" />
<br />
</td>
</tr>
<tr>
<td>
<p style="float:left; color:#FFF; padding-right:5px;">State/Zip</p>
<select name="states">
<option value="alabama">AL</option>
<option value="alaska">AK</option>
<option value="arizona">AZ</option>
<option value="georgia">GA</option>
<option value="kentucky">KY</option>
<option value="louisiana">LA</option>
<option value="nebraska">NE</option>
<option value="nevada">NV</option>
<option value="new hampshire">NH</option>
<option value="new jersey">NJ</option>
<option value="new york">NY</option>
<option value="north carolina">NC</option>
<option value="washington">WA</option>
<option value="west verginia">WV</option>
</select>
<input type="text" size="8" maxlength="7" name="zip" value="Zip Code" onFocus="if(this.value == 'Zip Code') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Zip Code';}" />
</td>
</tr>
<tr>
<td>
<textarea cols="28" rows="6" onblur="if(this.value=='') this.value='Leave a message'" onfocus="if(this.value =='Leave a message' ) this.value=''">Leave a message</textarea>
</td>
</tr>
<tr>
<td height="16">
<input type="submit" name="submit_order" id="sendFormBtn" />
</td>
</tr>
</table>
</form>