Jump to content

print text from javascript


westman
 Share

Recommended Posts

hi all its me again ;) i am macking a form to be sent to javascript and then the info from the form send to a divi have this so fare...

<script src="../js/jquery-1.4.2.js" type="text/javascript"></script><script language="javascript" type="text/javascript"> function sendname ( ) {    var name1 = $("#name1");outname1 = document.getElementById("first");if (name1.val() == "") {		   $("#results").html('<img src="../image/round_error.png" alt="Error" width="31" height="30" />   Please type a first name.').show().fadeOut(6000);	  }else{outname1.textContent = name1;} }</script>

but the last part or my code is not working. if i use...outname1.textContent = name1; oroutname1.innerHTML = name1; my output div value is "[object Object]"how do i fix the end of my script?

Link to comment
Share on other sites

I have not realy gone through jquery tutorial, but i think:

$('#name1')

, was ment to get an element with an id 'name1' right? It should be something like this:

 $('#name1').value;

to get the value of the form, instead of the object (element) itself.

Edited by eTianbun
Link to comment
Share on other sites

It's an object. I'm not sure what you want to show, but you should find the property or method of that object that gives the value you're looking for. It looks like the .val() method might be what you're looking for.

Link to comment
Share on other sites

got it working ;)

<script src="../js/jquery-1.4.2.js" type="text/javascript"></script><script language="javascript" type="text/javascript"> function sendname ( ) {    var name1 = $("#name1");outname1 = document.getElementById("first");if (name1.val() == "") {                   $("#results").html('<img src="../image/round_error.png" alt="Error" width="31" height="30" />   Please type a first name.').show().fadeOut(6000);          }else{outname1.innerHTML = name1.val();} }</script>

all i did was add.val() at the end of my code thank you so mush with the .val() thing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...