last day (14 days later) » 

6:52 AM
0
A: How to set Dropdown List default value based on user selection

SuyogTry using session for it. The php code: session_start(); $_SESSION['selectedCountry'] = $_POST['country']; Then you can use JQuery to make dropdown selected: $(document).ready(function(){ $(function() { $("#country").val("<?php echo $_SESSION['selectedCountry'];?>...

 
Not working. @Suyog
 
can you share your updated code?
 
i just add the session and the jquery in. I dont want to make others confused, hope you can understand.
 
okay, have you tried printing $_SESSION array? (just to make confirm that session has set).
 
yup tried before
 
6:52 AM
is it printing or giving any error?
 
totally no error
 
then try setting the SESSION a default value, so that if user has not POSTed any value, it will use the default value and if user POST any country then simply updte the SESSION.
bocz I tried code at my end before posting and it is working at my side.
 
actually my $country get from database, just not to make them confuse i said is from post method.
even default value doesnt work. Is there something wrong with jquery?
 
7:08 AM
no, the JQuery is fine. can you please tell me the output of print_r($_SESSION);
 
Array ( [userId] => admin [selectedCountry] => 355 )
 
oh.. okay. Have you checked your console just to make sure that there is no and JQuery error?
the session is working as expected here
 
Totally no error occur
Wait.. I saw one error
SyntaxError: expected expression, got '<'
 
7:25 AM
this is because you have missed closing bracket for some thins
try finding it
once your console will be of no error, the code should work
 
7:38 AM
<script>

$(document).ready(function(){
$(function() {
$("#country").val("<?php echo $_SESSION['selectedCountry']; ?>");
});
})


</script>
dont see any missing bracket
 
8:37 AM
solved ?
 
8:50 AM
nope
script>

$(document).ready(function(){
$(function() {
$("#country").val("<?php echo $_SESSION['selectedCountry']; ?>");
});
})


</script>
no missing bracket right?
<script>
 
9:19 AM
?
 

last day (14 days later) »