Read Data From Html Select Tag Before Sending To Php
I need to send a option to a PHP script, but the instead of a user clicking on a submit button, they simply click a type link. For instance: So the user will select 1, then clic
Solution 1:
You Have to use <form>
tag to make this possible or use ajax submit tu submit your form with <form>
you can do in this way
<formaction="next.php"method="POST"><selectname="test"><optionvalue="1">1</option></select><!-- Then after this don't use anchor tag <a> use input submit instead--><inputtype="submit"name="submit"value="Next"/></form>
Or you can also submit it with <button>
:
<formaction="next.php"method="POST"><selectname="test"><optionvalue="1">1</option></select><!-- Then after this don't use anchor tag <a> use button instead--><buttontype="submit">Next</button></form>
as you mentioned in question you want to get the value of select before submit to php you can use jQuery ajax
to do this look below
<formid="my_form"action=""><selectid="my_tag"name="test"><optionvalue="1">1</option></select><buttontype="submit">Next</button></form>
Ajax:
$('#my_form').submit(function(e){
if($('#my_tag').val() !== '') {
var select = $('#my_tag').val();
$.ajax({
type: 'Get', // Could be GET/POSTurl: 'php.php?select='+select, //targeting url with value from select tagsuccess: function(data){
alert(data); // alerting the data which php file returned.
}
});
} else {
alert('error'); // if select tag is empty we will show an error.
}
e.preventDefault();
});
Post a Comment for "Read Data From Html Select Tag Before Sending To Php"