1

I have the following code:

<form id="buttonForm" action = "/goSomeWhere" method="post" >
    <input type="submit" name="bnext" value="Next Page" >
    <input type="submit" name="bprevious" value="Previous Page" >
</form>

When either one of this two buttons are submitted I receive "bnext" or "bprevious" values in Django View request.POST so I can further construct the logic that I need.

But when I'm trying to insert some javascript for the second button I loose those values:

<input type="submit" name="bnext" value="Next Page" >
<input type="submit" name="bprevious" id="bpid" onclick="disable()" value="Previous Page" >

function disable()
{
     document.getElementById("bpid").disabled = true;
     document.getElementById("buttonForm").submit();
}

There is a way to do this and still receiving input names values ?

2 Answers 2

1

Sorry I didn't fully understood that what you are trying to do

If you are trying to stop form submission then:

function disable() {

   document.getElementById("bpid").disabled = true;

   document.getElementById("buttonForm").preventDefault();
 }

If you want that client should not click previous button again then, it is best to change inputType submit to hidden:

function disable() {
    document.getElementById("bpid").type="hidden";
    document.getElementById("buttonForm").submit();
 }

Or

create new <input type=hidden>, set name values ,append to form and submit it:

function disable() {
   document.getElementById("bpid"). disabled=true;
   newip= document.createElement("input");
   newip.type="hidden";
   newip.name="bprevious";
   newip.value="Previous Page";

document.getElementById("buttonForm").appendChild(newip);


document.getElementById("buttonForm").submit();
 }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Rk003. This was exactly what I was looking for: function disable() { document.getElementById("bpid").type="hidden"; document.getElementById("buttonForm").submit(); }
0

try to use button instead input like this

<button name="bprevious" id='bpid' onclick='disable()' value="Previous Page">Previous Page</button>

3 Comments

Same thing happens when I'm using button tag: I'm not receiving any values in the request.POST as I do without the javascript.
have you set the value in the button tag?
Did but still ...the same.

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.