I am trying to change the label of the ‘Save’ button to ‘Next’ using javascript and without having to click on Save first.
<input type="button" name="ctl01$SaveButton" value="Save" onclick="if(this.disabled)return false;accountCreatorInstance_ctl01_TemplateBody_WebPartManager1_gwpciNewContactAccountCreatorCommon_ciNewContactAccountCreatorCommon.ShowErrors();if(!RunAllValidators(new Array('52503d2c-d362-4864-a72d-5f883619889d'), true)) return false;this.disabled='disabled';WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("ctl01$SaveButton", "", true, "", "", false, true))" id="ctl01_SaveButton" title="Save" class="PrimaryButton TextButton Save" data-ajaxupdatedcontrolid="ContentDiv" translate="yes">
I’ve tried many different versions but nothing seems to work. I’m no JS expert so any help is appreciated.
document.getElementById(‘ctl01_SaveButton’).innerHTML = ‘Next’;
I just want the Save button to show ‘Next’ instead of Save.
2
Answers
use
value
, notinnerHTML
property to change things here.It looks like your button is an
<input>
element with thevalue
attribute set to "Save". To change the text on the button using JavaScript, you should update thevalue
attribute. Here’s how you can do it:This line of code finds the element with the ID ‘ctl01_SaveButton’ and updates its
value
attribute to ‘Next’, effectively changing the text displayed on the button.Make sure to execute this JavaScript code after the page has loaded or after the button element has been created in the DOM. You can place the script in a
<script>
tag at the end of your HTML body or use an event listener to run the code when the document is ready.This ensures that the script runs after the HTML has been fully loaded.