Jump to content
Sign in to follow this  
westman

print text from javascript

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?

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Why not use js instead? Dont realy know why you are geting that:

name1=document.getElementById('name1').value;outname1=document.getElementById('first');if(name1==''){/*You can add jquery here*/}else{outname1.innerHTML=name1}

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...