How to insert the value of a javascript alert box with input type text into html paragraphs

+1 Jae Phan · March 19, 2015
I'm actually using external jquery for this... and the code is 

    $(document).ready(function() {
  var userName = window.prompt("Please Enter Your Name", "Text");
});

so once the page is opened an alert box with Please Enter Your Name pops up and I want whatever value (the user's name) is typed into the input field to be placed in certain parts of the paragraph in my html file

<p> Welcome, (and i want their name here)</p>

Is this possible? Thank you in advance. :)

Post a Reply

Replies

Oldest  Newest  Rating
0 Sho Carter · March 30, 2015
Well, if it's going to work on the same page, you can do it this way:

HTML Page:
Hello, my name is 





jQuery file:

$( function() {

var Paragraph = $( '#paragraph' ).html();
var UserName = window.prompt( 'Please Enter Your Name', 'User1' );
var DynamicName = $( 'span#dynamicName');

if (UserName == '')
{
Username = 'User1';
}

DynamicName.html( UserName );
});
0 william appiah-dankwah · March 31, 2015
thats a good idea? it might be harder in javerscript
0 Sho Carter · April 1, 2015
This is jQuery...
  • 1

Javascript

107,332 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators