1

I'm trying to use the attr method to change the value of a form submit button. I want the value of the input to change from "Save log entry" to "Different log entry". It works when I try it on http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_attr_set, but not on my own page. On my page, the value stays as the original.

(The .text method is working and successfully changes the header)

JS

switch (theValue){
    case "hp1":
        var treatmentNumber = 1;
        //alert(treatmentNumber);
        $.mobile.changePage ("1.html#treatment");
        $("#save").attr("value","Different save log entry");
        $("#pageHeader").text("HP X1");
        break;  

HTML

<input type="submit" id="save" onclick="saveForm()" value="Save log entry"/>
Christn
  • 41
  • 5
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a *specific problem or error* and *the shortest code necessary* to reproduce it **in the question itself**. Questions without **a clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve) – elixenide Apr 23 '16 at 15:44
  • Use`$("#save").val(","Different save log entry");` – hr_117 Apr 23 '16 at 15:48
  • http://stackoverflow.com/questions/4837133/whats-the-difference-between-jquery-val-and-attrvalue – Bergi Apr 23 '16 at 16:11
  • @Christn do you have some other element's with `id save` on the page? – The Process Apr 23 '16 at 16:47
  • @itsgoingdown It's the only "save" on the page – Christn Apr 24 '16 at 03:41

2 Answers2

0
Try This:

$('#save').text('Value Changed');
Shantanu Madane
  • 617
  • 5
  • 14
0

You could try something like this to pass a variable into the value:

var stringentry = "Different log entry";
$("#save").val(stringentry);