Replace Input Field with Text

in Script development
Subscribe to Replace Input Field with Text 5 posts, 4 voices



mike cupcake Scriptwright
FirefoxMacintosh

You can get the value of the text field with:

var textField = document.getElementById("ContentPlaceHolder1_tbCustTelephone1");
var phoneNumber = textField.value;

then you could create a new DIV containing the value:

var showNumber = document.createElement("div");
showNumber.textContent = phoneNumber;

then insert the DIV somewhere into the document using appendChild or insertBefore

 
Roger Faught User
FirefoxWindows

Thanks for the reply - this is the best way to do it I think. I tried by the ID and here by the name:


var textField = document.getElementsByName("ctl00$ContentPlaceHolder1$tbCustTelephone1");
var phoneNumber = textField.value;
var showNumber = document.createElement("showphone1");
showNumber.textContent = phoneNumber;
document.body.appendchild(showNumber);

The script seems to be enabled on the page in Greasemonkey but nothing happens. The page source does not show any changes. Any clue what I'm doing wrong?

 
mike cupcake Scriptwright
FirefoxWindows

getElementsByName returns an array rather than a single element so you'd need to reference it with textField[0].value , why are you using that instead of getElementById ?

no idea why you've changed the createElement from 'div' to 'showphone1' , that might prevent it from being visible - I'm not sure.

you can use the Error Console to see where problems are occuring:
https://developer.mozilla.org/en/Error_Console

 
LouCypher Scriptwright
Safari

JavaScript doesn't manipulate the source. It manipulates the DOM.

 
Jefferson Scher Scriptwright
FirefoxWindows

Roger Faught wrote:
The page source does not show any changes. Any clue what I'm doing wrong?
To see the source as it has been changed by scripts, select the relevant part of the page, right-click, and use View Selection Source.