How to fill specific SelectField with the data returned from ajax call?How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?How to manage a redirect request after a jQuery Ajax callHow to insert an item into an array at a specific index (JavaScript)?jQuery how to find an element based on a data-attribute value?jQuery: Return data after ajax call successAjax request returns 200 OK, but an error event is fired instead of successHow to make an AJAX call without jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow do I return the response from an asynchronous call?How to create chained selectfield in flask without refreshing the page?

How to precisely measure small charges?

How does The Fools Guild make its money?

Why should public servants be apolitical?

Acceptable to cut steak before searing?

SQL Minimum Row count

How can glass marbles naturally occur in a desert?

How to relate a binned pdf to a pdf, taking into account how the data is binned?

As a 16 year old, how can I keep my money safe from my mother?

How to mark beverage cans in a cooler for a blind person?

How do Mogwai reproduce?

How many numbers in the matrix?

Best gun to modify into a monsterhunter weapon?

A question about 'reptiles and volatiles' to describe creatures

Generator for parity?

During the Space Shuttle Columbia Disaster of 2003, Why Did The Flight Director Say, "Lock the doors."?

How do we avoid CI-driven development...?

How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?

Non-OR journals which regularly publish OR research

How can I read one message at a time from /var/mail

How do I explain to a team that the project they will work on for six months will certainly be cancelled?

Are there any differences in causality between linear and logistic regression?

Send different event confirmation emails

Is this cheap "air conditioner" able to cool a room?

Can a College of Swords bard use Blade Flourishes multiple times in a turn?



How to fill specific SelectField with the data returned from ajax call?


How can I get jQuery to perform a synchronous, rather than asynchronous, Ajax request?How to manage a redirect request after a jQuery Ajax callHow to insert an item into an array at a specific index (JavaScript)?jQuery how to find an element based on a data-attribute value?jQuery: Return data after ajax call successAjax request returns 200 OK, but an error event is fired instead of successHow to make an AJAX call without jQuery?Pure JavaScript equivalent of jQuery's $.ready() - how to call a function when the page/DOM is ready for itHow do I return the response from an asynchronous call?How to create chained selectfield in flask without refreshing the page?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















Update later... I finally get my problem solved. I just wonder if there is a way doing this more elegant?



I'm at the very beginning of programing with Python3, Flask and Jquery.



What I aim to do is that making one SelectField change its value(s) based on another SelectField's option. Just like, when I choose US as country, then automatically load states(say, New York/Washington, D.C./...) from database with ajax help.



Now I could get data using ajax call, which means I could see the response in debug mode of Browser. I just do not know how to fill the specific SelectField with the response data. Below is the relevant code snippet. Thanks in advance for your time.



choose.html



<html>
<head>...</head>
<body>
...
<div class="row">
<form action="url_for('some_view_function')" method="post">
...
<div class="col-md-4 col-sm-4 col-xs-12">
form.country(class="form-control select2_single")
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
form.state(class="form-control select2_single")
</div>
...
</form>
</div>
...
<script>
$(document).ready(function()
$("#country").change(function()
country_id=$("#country").val();
$.get(" url_for('get_states_by_country') ",
"country_id":country_id,
function(data, status)
if (status == 'success')
// What should I do here with data?

);
);
);
</script>
</body>
</html>


view_function.py



@app.route('/obtain/states', methods='GET', 'POST')
def get_states_by_country():
country_id = request.args.get("country_id")

states = State.query.filter_by(
country_id=country_id
)
return jsonify(
int(s.state_id): s.state_name
for s in states
)


form.py



class LinkChooseForm(Form):
country = SelectField(label='Country')
state = SelectField(label='State')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.country.choices = [(c.id, c.name) for c in Country.query.all()]
self.state.choices = [] # I leave it empty when initiating


Update-1:

The data is json format. Mock data below. The key would be value of <option>, and value would be text of <option>.




"bash", "desc_for_bash",
"csh", "desc_for_csh",
...



Update-2:

With @Deepak's help, I finally solved this problem. The issue I mentioned under @Deepak's answer(form doesn't accept select option) is post wrong. In fact, form does accept the select option on my html page. I debug that and find out I miss to reset state.choices in my action function. You could notice that I leave the state.choices empty when initiating form object. But flask-wtf would validate that if your choice on page is one of state.choices. Which is obviously not, since I leave it empty. So I must reset it with request.form.get('state') to meet flask-wtf's validation. Below is submit function.



@app.route('/test', methods='GET', 'POST')
def some_view_function():
form = LinkChooseForm(**request.view_args)

if request.method == 'POST':
# The most important part here.
form.state.choices = [(request.form.get('state'), "")]

if form.validate_on_submit():
action_entity = ActionEntity()
action_entity.do(form)
return redirect(url_for('.another_view_function'))
else:
# reset it as empty again
form.state.choices = []

return render_template(
'result.html',
form=form
)









share|improve this question


























  • why cant you use plugins for that.why are you dumping the db

    – Obito Uchiha
    Mar 27 at 4:41











  • cssscript.com/demo/… please refer this.hope this helps

    – Obito Uchiha
    Mar 27 at 4:42












  • @Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

    – Light.G
    Mar 27 at 4:55











  • can you post your json data or a mock json so that i can write the code

    – Obito Uchiha
    Mar 27 at 4:56












  • @Deepak I edited my post, is that enough? Thanks.

    – Light.G
    Mar 27 at 5:37

















1















Update later... I finally get my problem solved. I just wonder if there is a way doing this more elegant?



I'm at the very beginning of programing with Python3, Flask and Jquery.



What I aim to do is that making one SelectField change its value(s) based on another SelectField's option. Just like, when I choose US as country, then automatically load states(say, New York/Washington, D.C./...) from database with ajax help.



Now I could get data using ajax call, which means I could see the response in debug mode of Browser. I just do not know how to fill the specific SelectField with the response data. Below is the relevant code snippet. Thanks in advance for your time.



choose.html



<html>
<head>...</head>
<body>
...
<div class="row">
<form action="url_for('some_view_function')" method="post">
...
<div class="col-md-4 col-sm-4 col-xs-12">
form.country(class="form-control select2_single")
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
form.state(class="form-control select2_single")
</div>
...
</form>
</div>
...
<script>
$(document).ready(function()
$("#country").change(function()
country_id=$("#country").val();
$.get(" url_for('get_states_by_country') ",
"country_id":country_id,
function(data, status)
if (status == 'success')
// What should I do here with data?

);
);
);
</script>
</body>
</html>


view_function.py



@app.route('/obtain/states', methods='GET', 'POST')
def get_states_by_country():
country_id = request.args.get("country_id")

states = State.query.filter_by(
country_id=country_id
)
return jsonify(
int(s.state_id): s.state_name
for s in states
)


form.py



class LinkChooseForm(Form):
country = SelectField(label='Country')
state = SelectField(label='State')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.country.choices = [(c.id, c.name) for c in Country.query.all()]
self.state.choices = [] # I leave it empty when initiating


Update-1:

The data is json format. Mock data below. The key would be value of <option>, and value would be text of <option>.




"bash", "desc_for_bash",
"csh", "desc_for_csh",
...



Update-2:

With @Deepak's help, I finally solved this problem. The issue I mentioned under @Deepak's answer(form doesn't accept select option) is post wrong. In fact, form does accept the select option on my html page. I debug that and find out I miss to reset state.choices in my action function. You could notice that I leave the state.choices empty when initiating form object. But flask-wtf would validate that if your choice on page is one of state.choices. Which is obviously not, since I leave it empty. So I must reset it with request.form.get('state') to meet flask-wtf's validation. Below is submit function.



@app.route('/test', methods='GET', 'POST')
def some_view_function():
form = LinkChooseForm(**request.view_args)

if request.method == 'POST':
# The most important part here.
form.state.choices = [(request.form.get('state'), "")]

if form.validate_on_submit():
action_entity = ActionEntity()
action_entity.do(form)
return redirect(url_for('.another_view_function'))
else:
# reset it as empty again
form.state.choices = []

return render_template(
'result.html',
form=form
)









share|improve this question


























  • why cant you use plugins for that.why are you dumping the db

    – Obito Uchiha
    Mar 27 at 4:41











  • cssscript.com/demo/… please refer this.hope this helps

    – Obito Uchiha
    Mar 27 at 4:42












  • @Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

    – Light.G
    Mar 27 at 4:55











  • can you post your json data or a mock json so that i can write the code

    – Obito Uchiha
    Mar 27 at 4:56












  • @Deepak I edited my post, is that enough? Thanks.

    – Light.G
    Mar 27 at 5:37













1












1








1








Update later... I finally get my problem solved. I just wonder if there is a way doing this more elegant?



I'm at the very beginning of programing with Python3, Flask and Jquery.



What I aim to do is that making one SelectField change its value(s) based on another SelectField's option. Just like, when I choose US as country, then automatically load states(say, New York/Washington, D.C./...) from database with ajax help.



Now I could get data using ajax call, which means I could see the response in debug mode of Browser. I just do not know how to fill the specific SelectField with the response data. Below is the relevant code snippet. Thanks in advance for your time.



choose.html



<html>
<head>...</head>
<body>
...
<div class="row">
<form action="url_for('some_view_function')" method="post">
...
<div class="col-md-4 col-sm-4 col-xs-12">
form.country(class="form-control select2_single")
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
form.state(class="form-control select2_single")
</div>
...
</form>
</div>
...
<script>
$(document).ready(function()
$("#country").change(function()
country_id=$("#country").val();
$.get(" url_for('get_states_by_country') ",
"country_id":country_id,
function(data, status)
if (status == 'success')
// What should I do here with data?

);
);
);
</script>
</body>
</html>


view_function.py



@app.route('/obtain/states', methods='GET', 'POST')
def get_states_by_country():
country_id = request.args.get("country_id")

states = State.query.filter_by(
country_id=country_id
)
return jsonify(
int(s.state_id): s.state_name
for s in states
)


form.py



class LinkChooseForm(Form):
country = SelectField(label='Country')
state = SelectField(label='State')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.country.choices = [(c.id, c.name) for c in Country.query.all()]
self.state.choices = [] # I leave it empty when initiating


Update-1:

The data is json format. Mock data below. The key would be value of <option>, and value would be text of <option>.




"bash", "desc_for_bash",
"csh", "desc_for_csh",
...



Update-2:

With @Deepak's help, I finally solved this problem. The issue I mentioned under @Deepak's answer(form doesn't accept select option) is post wrong. In fact, form does accept the select option on my html page. I debug that and find out I miss to reset state.choices in my action function. You could notice that I leave the state.choices empty when initiating form object. But flask-wtf would validate that if your choice on page is one of state.choices. Which is obviously not, since I leave it empty. So I must reset it with request.form.get('state') to meet flask-wtf's validation. Below is submit function.



@app.route('/test', methods='GET', 'POST')
def some_view_function():
form = LinkChooseForm(**request.view_args)

if request.method == 'POST':
# The most important part here.
form.state.choices = [(request.form.get('state'), "")]

if form.validate_on_submit():
action_entity = ActionEntity()
action_entity.do(form)
return redirect(url_for('.another_view_function'))
else:
# reset it as empty again
form.state.choices = []

return render_template(
'result.html',
form=form
)









share|improve this question
















Update later... I finally get my problem solved. I just wonder if there is a way doing this more elegant?



I'm at the very beginning of programing with Python3, Flask and Jquery.



What I aim to do is that making one SelectField change its value(s) based on another SelectField's option. Just like, when I choose US as country, then automatically load states(say, New York/Washington, D.C./...) from database with ajax help.



Now I could get data using ajax call, which means I could see the response in debug mode of Browser. I just do not know how to fill the specific SelectField with the response data. Below is the relevant code snippet. Thanks in advance for your time.



choose.html



<html>
<head>...</head>
<body>
...
<div class="row">
<form action="url_for('some_view_function')" method="post">
...
<div class="col-md-4 col-sm-4 col-xs-12">
form.country(class="form-control select2_single")
</div>
<div class="col-md-4 col-sm-4 col-xs-12">
form.state(class="form-control select2_single")
</div>
...
</form>
</div>
...
<script>
$(document).ready(function()
$("#country").change(function()
country_id=$("#country").val();
$.get(" url_for('get_states_by_country') ",
"country_id":country_id,
function(data, status)
if (status == 'success')
// What should I do here with data?

);
);
);
</script>
</body>
</html>


view_function.py



@app.route('/obtain/states', methods='GET', 'POST')
def get_states_by_country():
country_id = request.args.get("country_id")

states = State.query.filter_by(
country_id=country_id
)
return jsonify(
int(s.state_id): s.state_name
for s in states
)


form.py



class LinkChooseForm(Form):
country = SelectField(label='Country')
state = SelectField(label='State')

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.country.choices = [(c.id, c.name) for c in Country.query.all()]
self.state.choices = [] # I leave it empty when initiating


Update-1:

The data is json format. Mock data below. The key would be value of <option>, and value would be text of <option>.




"bash", "desc_for_bash",
"csh", "desc_for_csh",
...



Update-2:

With @Deepak's help, I finally solved this problem. The issue I mentioned under @Deepak's answer(form doesn't accept select option) is post wrong. In fact, form does accept the select option on my html page. I debug that and find out I miss to reset state.choices in my action function. You could notice that I leave the state.choices empty when initiating form object. But flask-wtf would validate that if your choice on page is one of state.choices. Which is obviously not, since I leave it empty. So I must reset it with request.form.get('state') to meet flask-wtf's validation. Below is submit function.



@app.route('/test', methods='GET', 'POST')
def some_view_function():
form = LinkChooseForm(**request.view_args)

if request.method == 'POST':
# The most important part here.
form.state.choices = [(request.form.get('state'), "")]

if form.validate_on_submit():
action_entity = ActionEntity()
action_entity.do(form)
return redirect(url_for('.another_view_function'))
else:
# reset it as empty again
form.state.choices = []

return render_template(
'result.html',
form=form
)






jquery ajax python-3.x flask-wtforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 27 at 7:23







Light.G

















asked Mar 27 at 4:24









Light.GLight.G

7195 silver badges14 bronze badges




7195 silver badges14 bronze badges















  • why cant you use plugins for that.why are you dumping the db

    – Obito Uchiha
    Mar 27 at 4:41











  • cssscript.com/demo/… please refer this.hope this helps

    – Obito Uchiha
    Mar 27 at 4:42












  • @Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

    – Light.G
    Mar 27 at 4:55











  • can you post your json data or a mock json so that i can write the code

    – Obito Uchiha
    Mar 27 at 4:56












  • @Deepak I edited my post, is that enough? Thanks.

    – Light.G
    Mar 27 at 5:37

















  • why cant you use plugins for that.why are you dumping the db

    – Obito Uchiha
    Mar 27 at 4:41











  • cssscript.com/demo/… please refer this.hope this helps

    – Obito Uchiha
    Mar 27 at 4:42












  • @Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

    – Light.G
    Mar 27 at 4:55











  • can you post your json data or a mock json so that i can write the code

    – Obito Uchiha
    Mar 27 at 4:56












  • @Deepak I edited my post, is that enough? Thanks.

    – Light.G
    Mar 27 at 5:37
















why cant you use plugins for that.why are you dumping the db

– Obito Uchiha
Mar 27 at 4:41





why cant you use plugins for that.why are you dumping the db

– Obito Uchiha
Mar 27 at 4:41













cssscript.com/demo/… please refer this.hope this helps

– Obito Uchiha
Mar 27 at 4:42






cssscript.com/demo/… please refer this.hope this helps

– Obito Uchiha
Mar 27 at 4:42














@Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

– Light.G
Mar 27 at 4:55





@Deepak Thanks for your time. But what I put up here is just an example. In fact, I have two SelectFields with specific business meaning, not country and state.

– Light.G
Mar 27 at 4:55













can you post your json data or a mock json so that i can write the code

– Obito Uchiha
Mar 27 at 4:56






can you post your json data or a mock json so that i can write the code

– Obito Uchiha
Mar 27 at 4:56














@Deepak I edited my post, is that enough? Thanks.

– Light.G
Mar 27 at 5:37





@Deepak I edited my post, is that enough? Thanks.

– Light.G
Mar 27 at 5:37












1 Answer
1






active

oldest

votes


















1














var data = '"bash":"desc_for_bash","csh":"desc_for_csh, city"';//Your JSON data
data = JSON.parse(data); //To parse your JSON data
var str=''
for(d in data)
str+='<option value="'+d+'">'+data[d]+'</option>'

$("#your_select_id").html(str) //For adding options to select





share|improve this answer



























  • Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

    – Light.G
    Mar 27 at 6:29











  • But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

    – Light.G
    Mar 27 at 6:32











  • are you telling that the form does'nt accept SelectField value on submit?

    – Obito Uchiha
    Mar 27 at 6:36












  • can you please post your form submit code

    – Obito Uchiha
    Mar 27 at 6:37






  • 1





    Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

    – Light.G
    Mar 27 at 7:26










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369793%2fhow-to-fill-specific-selectfield-with-the-data-returned-from-ajax-call%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














var data = '"bash":"desc_for_bash","csh":"desc_for_csh, city"';//Your JSON data
data = JSON.parse(data); //To parse your JSON data
var str=''
for(d in data)
str+='<option value="'+d+'">'+data[d]+'</option>'

$("#your_select_id").html(str) //For adding options to select





share|improve this answer



























  • Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

    – Light.G
    Mar 27 at 6:29











  • But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

    – Light.G
    Mar 27 at 6:32











  • are you telling that the form does'nt accept SelectField value on submit?

    – Obito Uchiha
    Mar 27 at 6:36












  • can you please post your form submit code

    – Obito Uchiha
    Mar 27 at 6:37






  • 1





    Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

    – Light.G
    Mar 27 at 7:26















1














var data = '"bash":"desc_for_bash","csh":"desc_for_csh, city"';//Your JSON data
data = JSON.parse(data); //To parse your JSON data
var str=''
for(d in data)
str+='<option value="'+d+'">'+data[d]+'</option>'

$("#your_select_id").html(str) //For adding options to select





share|improve this answer



























  • Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

    – Light.G
    Mar 27 at 6:29











  • But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

    – Light.G
    Mar 27 at 6:32











  • are you telling that the form does'nt accept SelectField value on submit?

    – Obito Uchiha
    Mar 27 at 6:36












  • can you please post your form submit code

    – Obito Uchiha
    Mar 27 at 6:37






  • 1





    Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

    – Light.G
    Mar 27 at 7:26













1












1








1







var data = '"bash":"desc_for_bash","csh":"desc_for_csh, city"';//Your JSON data
data = JSON.parse(data); //To parse your JSON data
var str=''
for(d in data)
str+='<option value="'+d+'">'+data[d]+'</option>'

$("#your_select_id").html(str) //For adding options to select





share|improve this answer















var data = '"bash":"desc_for_bash","csh":"desc_for_csh, city"';//Your JSON data
data = JSON.parse(data); //To parse your JSON data
var str=''
for(d in data)
str+='<option value="'+d+'">'+data[d]+'</option>'

$("#your_select_id").html(str) //For adding options to select






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 27 at 6:33

























answered Mar 27 at 5:55









Obito UchihaObito Uchiha

1,3191 gold badge2 silver badges15 bronze badges




1,3191 gold badge2 silver badges15 bronze badges















  • Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

    – Light.G
    Mar 27 at 6:29











  • But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

    – Light.G
    Mar 27 at 6:32











  • are you telling that the form does'nt accept SelectField value on submit?

    – Obito Uchiha
    Mar 27 at 6:36












  • can you please post your form submit code

    – Obito Uchiha
    Mar 27 at 6:37






  • 1





    Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

    – Light.G
    Mar 27 at 7:26

















  • Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

    – Light.G
    Mar 27 at 6:29











  • But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

    – Light.G
    Mar 27 at 6:32











  • are you telling that the form does'nt accept SelectField value on submit?

    – Obito Uchiha
    Mar 27 at 6:36












  • can you please post your form submit code

    – Obito Uchiha
    Mar 27 at 6:37






  • 1





    Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

    – Light.G
    Mar 27 at 7:26
















Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

– Light.G
Mar 27 at 6:29





Thanks a lot, it works for me. Only an issue, but it's my fault. According to my code in view_function.py, you could see the data is already json object. So I just remove the data=Json.parse(data); part. You may put up some description for your answer.

– Light.G
Mar 27 at 6:29













But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

– Light.G
Mar 27 at 6:32





But it still blocks me when submitting the whole form. Seems like the page doesn't accept any option for this SelectField. Maybe you could help further. Thanks again.

– Light.G
Mar 27 at 6:32













are you telling that the form does'nt accept SelectField value on submit?

– Obito Uchiha
Mar 27 at 6:36






are you telling that the form does'nt accept SelectField value on submit?

– Obito Uchiha
Mar 27 at 6:36














can you please post your form submit code

– Obito Uchiha
Mar 27 at 6:37





can you please post your form submit code

– Obito Uchiha
Mar 27 at 6:37




1




1





Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

– Light.G
Mar 27 at 7:26





Thank u Deepak, it turns out my code's wrong, not "form doesn't accept SelectFeild value on submit". I've already solved that. I just wonder: is there a way doing this more elegant? I mean on javascript part mainly. I just do not want to makeup html code in <script>.

– Light.G
Mar 27 at 7:26








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55369793%2fhow-to-fill-specific-selectfield-with-the-data-returned-from-ajax-call%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

위키백과:대문 둘러보기 메뉴기부 안내모바일판 대문크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0CebuanoDeutschEnglishEspañolFrançaisItaliano日本語NederlandsPolskiPortuguêsРусскийSvenskaTiếng ViệtWinaray中文العربيةCatalàفارسیSrpskiУкраїнськаБългарскиНохчийнČeštinaDanskEsperantoEuskaraSuomiעבריתMagyarՀայերենBahasa IndonesiaҚазақшаBaso MinangkabauBahasa MelayuBân-lâm-gúNorskRomânăSrpskohrvatskiSlovenčinaTürkçe

용인 삼성생명 블루밍스 목차 통계 역대 감독 선수단 응원단 경기장 같이 보기 외부 링크 둘러보기 메뉴samsungblueminx.comeh선수 명단용인 삼성생명 블루밍스용인 삼성생명 블루밍스ehsamsungblueminx.comeheheheh