-1

If the selectbox is not selected then it will return null value, how does it possible? I have tried this code:

<select name="city" id="city" style="width:238px;height:40px;"><option value= NULL >Select City</option>@foreach($cityName as $city)<option value="{{$city->id}}"> {{$city->name}}</option>@endforeach</select>
Bowdzone
  • 3,827
  • 11
  • 39
  • 52
laravel
  • 11
  • 3

2 Answers2

0

You can't.

jQuery will always get a string when it tries to read the value of a select element.

The closest you could come would be to use an empty string (value="") or to test explicitly in JS:

var my_value = jQuery('select').val();
my_value = (my_value === "NULL") ? null : my_value;
Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
0

really simple ,I think it's just about html ,

<option value="" selected="selected"> ---- </option>

use this as a default selected item , and change the received value from "" to null in javascript if you want .

柯鴻儀
  • 613
  • 1
  • 10
  • 25