Faizan Qadri
Faizan Qadri

Reputation: 248

Text in div gets input from the form

following is my div and i want to know how can i get the input from the form lets say from textfield 'name' and display that input name instead of jhon in the following div, Kindly help!!

<div id='faix' class="bg4 w460 h430 tac poa dpn ">
                    <h4 class="fwb fs22 cf3 mb5 ff3 mt150 ">Thank you John for contacting us!</h4><h4 class="fwb fs22 cf3 mb5 ff3"> We will get in touch with you shortly.</h4>
                </div>

Upvotes: 0

Views: 269

Answers (2)

mgraph
mgraph

Reputation: 15338

html:

<form id="myForm">
  <input id="name" name="name" value=""/>
</form> 

js:

$("#myForm").submit(function(){
  $("#faix h4.mt150").empty().append("Thank you "+$("#name").val()+" for contacting us!");
    return false;
})​

demo : http://jsfiddle.net/BPXpb/1/

Upvotes: 0

Marco Johannesen
Marco Johannesen

Reputation: 13134

See http://jsfiddle.net/wfAgb/

//get the name
var Name = $('#name').val();
//replace John with the new name
$('.mt150').text($('.mt150').text().replace('John', Name));

You could with great benefit make span arounde the name so you can change it directly.

<h4 class="fwb fs22 cf3 mb5 ff3 mt150 ">Thank you <span id="formName">John</span> for contacting us!</h4>

And then do

var Name = $('#name').val();
$('#formName').text(Name);

Upvotes: 1

Related Questions