Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8394017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:57:25+00:00 2026-06-09T19:57:25+00:00

This is my function: The problem is that I don’t know how to add

  • 0

This is my function:
The problem is that I don’t know how to add “value” to the “link”.

   function add_subject_to_subjects_list() {
        var value = $("#id_name").val();
        var link = "/subject/create/"+value;
        show_subjects_list();
        $("#btn-create-subject").click(function() {
            $.post(link, function(data) {
                show_subjects_list();
                alert(data).hide("fast");
            });
        });
    }

Because of that my function post data to the different link: http://127.0.0.1:8000/subject/create/

But I want my link depends on value:
and it should look like:

http://127.0.0.1:8000/subject/create/some_value/ 

that’s the whole js for that page:

$(document).ready(function (){
    add_subject_to_subjects_list();
});

function show_subjects_list() {
    $.post("/subject/list/", function(data){
        for( var i=0; i<data.length; i++) {
            $("#list").append('<li>'+data[i]['fields']['name']+'</li><br>');
        };
    }, 'json');
}

function add_subject_to_subjects_list() {
    var value = $("#id_name").val();
    var link = "/subject/create/"+value;
    show_subjects_list();
    $("#btn-create-subject").click(function() {
        $.post(link, function(data) {
            show_subjects_list();
            alert(data).hide("fast");
        });
    });
}

that’s my server-side (I’m using Django/Python):

@csrf_exempt
def subjects_list(request):
    user = request.user
    subjects = Subjects.objects.filter(user__exact = user)
    result = serializers.serialize("json", subjects, fields=('name'))
    return HttpResponse(result)

@csrf_exempt
def new_subject(request, subject):
    subject, created= Subjects.objects.get_or_create( 
        name=subject,
        user=request.user,
        created_by=request.user)
    if created:
        message = "Subject was created"
    else:
        message = "No subject was added to the database"
    return HttpResponse(message)

and that’s my html:

{% block left-menu %}

    <div class="sidebar">
        <h3>Subjects</h3>
        <p> Enter subject name to add </p>
        <br>

        <div id="create-subject">
            <form method="post" action="."> {% csrf_token %}
                {{ subject_creation_form.as_p }}
                <input type="button" value="Create Subject" id="btn-create-subject" />
            </form>
        </div>

            <div id="subjects-list">
                <a id="append">myID</a>
                <ul id="list">

                </ul>
            </div>
        </div>
{% endblock %}

that’s the form for that html:

class SubjectCreationForm(forms.Form):
    name = forms.CharField(label="Subject Name", widget=forms.TextInput(attrs={'size':9}))

    class Meta:
        exclude = ('created_by', 'created_time', 'num_of_followers', 'vote')
    def clean_name(self):
        name = self.cleaned_data['name']
        if len(name)>1:
            return name
        else:
            raise forms.ValidationError("Subject name should be longer")
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:57:27+00:00Added an answer on June 9, 2026 at 7:57 pm

    like @nnnnnn suggested, first two line of code had to be placed inside $.post like that:

    ......
    $("#btn-create-subject").click(function() {
            var value = $("#id_name").val();
            var link = "/subject/create/"+value;
            $.post(link, function(data) {
                alert(data);
            });
    .......
    

    Thank to everybody)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this problem that I probably understand but don't know how to handle,
I've used this useful JQuery function that serializes nested elements. the problem is how
I'm having a problem with using this in js. I have a function that
Maddening problem here. When my page loads: <body onload=getClientDateTime();> It runs this function: document.getElementById('ClientDateTime').value=hello
I have some inherited JS code that uses this format: function main(param) { var
This is a problem that I don't understand because all the code validates. It's
I have a problem with a javascript set of functions that I made. This
Im having a problem with the XML in this function and many functions like
THIS IS THE FULL SCRIPT http://goo.gl/HoCxk I have a problem with this function: $('.message').click(function(){
I have this function above to create url slugs from posts title, the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.