0

So I have a form that I am submitting and the valueof the input button is "View Insight." When I submit the form using Request, I get a nasty string in the URL like Insight=View+Insight.

What I want it to say in the URL is "Insight=Confirmed". I tried using jquery to change the value of the button and it worked but you see it changing the value in the user interface. How do I change the value of what I want without showing the user?

Here is what I have so far:

JQUERY

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
    <script type="text/javascript">
            $(document).ready(function(){
      $("#savebtn").bind("click",function(){
        $(this).val('confirmed');
      });
    });
</script>

HTML

<form action="confirm4.php" method="request">
    <input type="submit" name="insights" id="savebtn" value="View Insights" />
</form>

2 Answers 2

1

You can change the input[type=submit] to button[type=submit] like so:

<form action="confirm4.php" method="request">
  <input type="hidden" name="Insight" value="Confirmed">
  <button type="submit" id="savebtn">View Insights</button>
</form>
Sign up to request clarification or add additional context in comments.

2 Comments

Although this would work, It seems like it is a bit intrusive. Thank you for your answer.
I don't see how it is intrusive. It is semantic, modern, and will work with or without the hidden attribute. Assuming the backend script doesn't require Insight=Confirmed You are welcome for the answer though. Heres something I urge you to look into: css-tricks.com/use-button-element
1

First, .bind is deprecated and you should be using .on instead.

Second, what you are looking for is

$("#savebtn").on("click",function(e){
    e.preventDefault(); //stop current submission

    var $this = $(this);
    $this.val('confirmed'); //change the value
    $this.off("click"); //unbind the handler
    $this.click(); //click the button again
});

1 Comment

Thank you Zachary, I was unaware that .bind was deprecated. This works perfectly. Thanks for explaining it thoroughly.

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.