[RESOLVED] drop down
Hello,
i have a problem with drop down menu, it doens't gives the value trough.
HTML Code:
<label> Boogschieten of Valkerij</label>
<select id = "keuze" name="keuze" >
<option value = ""> Keuze</option>
<option value = "Boogschieten"> Boogschieten</option>
<option value = "Valkerij"> Valkerij</option>
</select>
javascript :
Code:
var keuze = $("input#keuze").val();
if ( document.getElementById('keuze').selectedIndex == 0 ) {
$("#error").fadeIn().text("Gelieve een keuze te maken");
$("input#web").focus();
return false;
}
PHP Code:
<?php
//vars
$subject = $_POST [ 'subject' ];
$to = explode ( ',' , $_POST [ 'to' ] );
$from = $_POST [ 'email' ];
//data
$msg .= "KEUZE: " . $_POST [ 'keuze' ] . "<br>\n" ;
//Headers
$headers = "MIME-Version: 1.0\r\n" ;
$headers .= "Content-type: text/html; charset=UTF-8\r\n" ;
$headers .= "From: <" . $from . ">" ;
//send for each mail
foreach( $to as $mail ){
mail ( $mail , $subject , $msg , $headers );
}
?>
what I get for KEUZE in the email is : [object HTMLSelectElement]
Can you post your whole code? It's really hard to guess with the info you provided. But for starters,
$("input#keuze")
returns an empty set, because you are looking for select, not input.
Originally Posted by
haulin
Can you post your whole code? It's really hard to guess with the info you provided. But for starters,
$("input#keuze")
returns an empty set, because you are looking for select, not input.
HTML Code:
<script type="text/javascript" src="js/form_bestel-validation.js" > </script>
<form id="contactFormBestel" action="#" method="post" >
<fieldset>
<p>
<label> NAAM:</label>
<input name="name" id="name" type="text" />
</p>
<p>
<label> EMAIL:</label>
<input name="email" id="email" type="text" />
</p>
<p>
<label> TELEFOON:</label>
<input name="tele" id="tele" type="text" />
</p>
<p>
<label> ADRES:</label>
<input name="adres" id="adres" type="text" />
</p>
<p>
<label> Boogschieten of Valkerij</label>
<select id = "keuze" name="keuze" >
<option value = ""> Keuze</option>
<option value = "Boogschieten"> Boogschieten</option>
<option value = "Valkerij"> Valkerij</option>
</select>
</p>
<p>
<label> AANTAL BONNEN:</label>
<input name="bon" id="bon" type="text" />
</p>
<p>
<label> COMMENTAAR:</label>
<textarea name="comments" id="comments" rows="5" cols="20" > </textarea>
</p>
<!-- send mail configuration -->
<input type="hidden" value="info@boogschieteninbelgie.be" name="to" id="to" />
<input type="hidden" value="info@boogschieteninbelgie.be" name="from" id="from" />
<input type="hidden" value="Bestelling via nieuwe website" name="subject" id="subject" />
<input type="hidden" value="Bestel.php" name="sendMailUrl" id="sendMailUrl" />
<!-- ENDS send mail configuration -->
<p> <input type="button" value="SEND" name="submit" id="submit" /> </p>
</fieldset>
<p id="error" class="warning" > Message</p>
</form>
<p id="success" class="success" > Merci voor de aanvraag, we behandelen deze zo snel mogelijk.</p>
<!-- ENDS form -->
Code:
$(document).ready(function(){
// hide messages
$("#error").hide();
$("#success").hide();
// on submit...
$("#contactFormBestel #submit").click(function() {
$("#error").hide();
//required:
//name
var name = $("input#name").val();
if(name == ""){
$("#error").fadeIn().text("Gelieve u naam in te vullen");
$("input#name").focus();
return false;
}
// email
var email = $("input#email").val();
if(email == ""){
$("#error").fadeIn().text("Gelieve u email in te vullen");
$("input#email").focus();
return false;
}
// telefoon
var tele = $("input#tele").val();
if(tele == ""){
$("#error").fadeIn().text("Gelieve u telefoon in te vullen");
$("input#web").focus();
return false;
}
// adres
var adres = $("input#adres").val();
if(adres == ""){
$("#error").fadeIn().text("Gelieve u adres in te vullen");
$("input#web").focus();
return false;
}
// keuze lijst
var keuze = $("input#keuze").val();
if ( document.getElementById('keuze').selectedIndex == 0 ) {
$("#error").fadeIn().text("Gelieve een keuze te maken");
$("input#web").focus();
return false;
}
// Aantal bonnnen
var bon = $("input#bon").val();
if(bon == ""){
$("#error").fadeIn().text("Gelieve het aantal bonnen in te vullen");
$("input#web").focus();
return false;
}
// comments
var comments = $("#comments").val();
if(comments == ""){
$("#error").fadeIn().text("Gelieve u vraag in te vullen");
$("input#web").focus();
return false;
}
// send mail php
var sendMailUrl = $("#sendMailUrl").val();
//to, from & subject
var to = $("#to").val();
var from = $("#from").val();
var subject = $("#subject").val();
// data string
var dataString = 'name='+ name
+ '&email=' + email
+ '&tele=' + tele
+ '&adres=' + adres
+ '&keuze=' + keuze
+ '&bon=' + bon
+ '&comments=' + comments
+ '&to=' + to
+ '&from=' + from
+ '&subject=' + subject;
// ajax
$.ajax({
type:"POST",
url: sendMailUrl,
data: dataString,
success: success()
});
});
// on success...
function success(){
$("#success").fadeIn();
$("#contactFormBestel").fadeOut();
}
return false;
});
PHP Code:
<?php
//vars
$subject = $_POST [ 'subject' ];
$to = explode ( ',' , $_POST [ 'to' ] );
$from = $_POST [ 'email' ];
//data
$msg = "NAME: " . $_POST [ 'name' ] . "<br>\n" ;
$msg .= "EMAIL: " . $_POST [ 'email' ] . "<br>\n" ;
$msg .= "TELEFOON: " . $_POST [ 'tele' ] . "<br>\n" ;
$msg .= "ADRES: " . $_POST [ 'adres' ] . "<br>\n" ;
$msg .= "KEUZE: " . $_POST [ 'keuze' ] . "<br>\n" ;
$msg .= "AANTAL BONNEN: " . $_POST [ 'bon' ] . "<br>\n" ;
$msg .= "COMMENTS: " . $_POST [ 'comments' ] . "<br>\n" ;
//Headers
$headers = "MIME-Version: 1.0\r\n" ;
$headers .= "Content-type: text/html; charset=UTF-8\r\n" ;
$headers .= "From: <" . $from . ">" ;
//send for each mail
foreach( $to as $mail ){
mail ( $mail , $subject , $msg , $headers );
}
?>
Well, try what i suggested. Change this line:
var keuze = $("input#keuze").val();
to this:
var keuze = $("select #keuze").val();
however, you don't really need to specify the tag name, when you refer to the elements with IDs, because they are supposed to be unique anyway, so this should work, too:
var keuze = $("#keuze").val();
of course, so obvious...
Works great!
many thanks !
You can thank me by marking this thread Resolved ( On top of all these comments look for Thread tools )
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks