0

I would like to pass the name variable of a selected inputbox in my django template into a url without going through the django views or url.py. Is there an easy way to do this.

<div class="form-group">
    <label class="col-xs-3 control-label">Chapter</label>
    <div class="col-xs-5 selectContainer">
      <input class="form-control" type="text" name="chapter_text" value="1"></input>
    </div>
</div>

I want the name value of the input class to be passed into the name argument of the url in the div button below

<div class="form-group">
    <div class="col-xs-5 col-xs-offset-3">
      <div class="btn btn-default"><a href="{% url 'api:by_book' 'name' %}">Download</a></div>
    </div>
</div>

1 Answer 1

1

You should do it through javascript. Store your url value as a JS variable:

<script> my_url = "{% url 'api:by_book' 'name' %}"; </script>

Change the anchor to a button with a onClick event that calls a function. In that function you can build the URL with my_url and recovering the name of the input you want with JS. After that, make a redirection:

window.location = "http://www.yoururl.com";
Sign up to request clarification or add additional context in comments.

1 Comment

thanks for the advice @user2872782. I've just used JQuery to sort out everything

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.