Interval Grid
Interval Grid

Reputation: 187

Javascript window.alert change to text

I have an simple question,

How to change

window.alert ('Please input data into the \"Part No.\" field.');

to be just text, no alert

Please input data into the \"Part No.\" field.

Upvotes: 1

Views: 788

Answers (2)

Steven Moseley
Steven Moseley

Reputation: 16325

I assume you want to simply write it to your document? Include this in a <script> block in your <body>

document.write('<p>Please input data into the &quot;Part No.&quot; field.</p>');

EDIT: On rethinking this, I now believe that you want the message to appear after the input element. Here, assuming your input element is <input id="part_no_field" />

// Create a message node
var messageNode = document.createElement('p');
messageNode.innerText = 'Please input data into the &quot;Part No.&quot; field.';

// Find your "part number" field
var partField = document.getElementById('part_no_field');

// Append the message node after your "part number" field
if (partField.nextSibling) {
    partField.parentNode.insertBefore(messageNode, partField.nextSibling);
} else {
    partField.parentNode.appendChild(messageNode);
}

Upvotes: 1

Isaac
Isaac

Reputation: 11805

It depends where you want the text to be placed:

var text = 'Please input data into the \'Part No.\' field.'

//inside a div
div.innerHTML = text;

//the bottom of the body
document.body.innerHTML+=text;

//an input field
input.value = text;

//rewriting the document
document.open();
document.write(text);
document.close();

Upvotes: 1

Related Questions