Hi everyone,

I am in the process of building a website within our ERP/CRM system and have hit a road block.

I have a couple of form fields within my page...
I have an element that has a form label that cannot be changed via the system and was thinking about changing it on the fly with the getelementbyID and innerHtml methods.

I was thinking about writing a script that reads the page by using getElementById() and changing the value of the string that resides within that area.

I believe that to change the value I would use the innerHTML function. But i cant figure out how to do this ?

Can anyone show me how i could change a string value by using these methods to replace a string on a page ?

thanks in advance

If you just want to change the contents of the Text object or replace the given Text object with an entirely new one, the simplest possible way would be:

var e = document.getElementById("yourId");
if(e)  e.innerHTML = "Hi! I am the new text";

Or you can also do it this way.

<html>
<head>
<title><!--Sample--></title>
<script type="text/javascript">
<!--
window.onload = function()
{ document.getElementById('div1').innerText = 'Hello World!'; }
//-->
</script>
</head>
<body>
<p><div id="div1" onclick="this.innerHTML = '<font color=red>GoodBye World!</font>';">&nbsp;</div>
</p>
</body>
</html>

I have a couple of form fields within my page...
I have an element that has a form label that cannot be changed via the system and was thinking about changing it on the fly with the getelementbyID and innerHtml methods.

Give an ID to your LABEL f.i.: <label id="yourId" for=... element you like to change and use the provided solution procedure by: ~s.o.s~.

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.