944,111 Members | Top Members by Rank

Ad:
Nov 25th, 2006
0

Java script - wordwrap ?

Expand Post »
Could someone please assist me in modifying the following java script code so that it does a word wrap. It currently forms one long long single line.
Thank You ..Tim (I've spent 8 hours trying to solve it...frustrated!)

<p><b>Q10) Breed is not about traits as much as it is about pedigree. Pedigree means?</b><br>

<input type="button" name="submit" value="Answer!" style="FONT-WEIGHT: bold; BACKGROUND: blue; WIDTH: 100px; COLOR: white"
onclick="document.answer.Tim10.value = 'Having papers from the registering body that attest to their ancestry. A tracking registry.';">
<input name=Tim10 rows="2" cols="40" wrap="virtual" style="BORDER-RIGHT: medium none; BORDER-TOP: medium none; BORDER-LEFT: medium none; WIDTH: 1000px; BORDER-BOTTOM: medium none;color:red">
</p>

</p>
Last edited by Tim Stevenson; Nov 25th, 2006 at 8:50 pm. Reason: more information
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Tim Stevenson is offline Offline
1 posts
since Nov 2006
Nov 26th, 2006
0

Re: Java script - wordwrap ?

I'm sorry, I don't mean to sound mean-spirited or sarcastic, but try a JavaScript Forum. Java != JavaScript
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Nov 26th, 2006
0

Re: Java script - wordwrap ?

Secondly what you provided is not JavaScript only onClick action which take place on press of submit button. So put one and one together you are trying to steal somebody's work and have no idea what JavaScript is
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Nov 26th, 2006
0

Re: Java script - wordwrap ?

Hi there,

Actually the JavaScript is there and its working well, but which Attribute you want to add in textfiels that doesn’t support! With this tag (rows="2" cols="40"), you should use the textarea for this functionality,

[HTML]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script language="JavaScript" type="text/javascript">
//<![CDATA[

function get_Result()
{
document.answer.Tim10.value = "Having papers from the registering body "+ "\n" +"that attest to their ancestry. A tracking registry.";
document.answer.Tim10a.value = "Having papers from the registering body "+ "\n" +"that attest to their ancestry. A tracking registry.";
document.answer.Tim10.setAttribute("rows","5");
document.answer.Tim10.setAttribute("cols","40");
document.answer.Tim10a.setAttribute("rows","5");
document.answer.Tim10a.setAttribute("cols","40");
}
//]]>
</script>
</head>
<body>
<p><b>Q10) Breed is not about traits as much as it is about pedigree. Pedigree means?</b><br>
<form action="" method="post" name="answer">
<input type="button" name="submit" value="Answer!" onclick="get_Result();" />
<br />
<textarea name="Tim10"></textarea>
<br />
<input name="Tim10a" type="text"/>
</form>
</p>
</body>
</html>
[/HTML]

Regards,
Rahul Dev
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Nov 26th, 2006
0

Re: Java script - wordwrap ?

or you can use the DIV tag to show the Answer!

code is here:

put in head

HTML and CSS Syntax (Toggle Plain Text)
  1. <script language="JavaScript" type="text/javascript">
  2. //<![CDATA[
  3.  
  4. function get_Result()
  5. {
  6. var divAnswer = document.getElementById('myDiv');
  7. divAnswer.style.visibility = "visible";
  8. }
  9. //]]>
  10. </script>
  11. <style type="text/css">
  12. <!--
  13. #myDiv {
  14. visibility: hidden;
  15. }
  16. -->
  17. </style>

and this in Body
HTML and CSS Syntax (Toggle Plain Text)
  1. <p><b>Q10) Breed is not about traits as much as it is about pedigree. Pedigree means?</b><br>
  2. <form action="" method="post" name="answer">
  3. <input type="button" name="submit" value="Get Answer!" onclick="get_Result();" />
  4. </form>
  5. </p>
  6. <div id="myDiv">
  7. <p>Having papers from the registering body that attest to their ancestry. A tracking registry.</p>
  8. </div>
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Nov 28th, 2006
0

Re: Java script - wordwrap ?

Quote ...
onclick="document.answer.Tim10.value = 'Having papers from the registering body that attest to their ancestry. A tracking registry.';"
IS NOT a JavaScript, it is only action taken once button pressed, which will triget this action. So as it is on its own that code will do nothing
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 874
Code tags enforcer
peter_budo is offline Offline
6,659 posts
since Dec 2004
Nov 28th, 2006
0

Re: Java script - wordwrap ?

Quote ...
onclick="document.answer.Tim10.value = 'Having papers from the registering body that attest to their ancestry. A tracking registry.';"
onclick is a event

and "document.answer.Tim10.value" is a JavaScript

syntax : document.FormName.fieldName.value = "The value"

Like in this code I have used the two JavaScript syntax

1.) document.write("Strings")
2.) alert("Strings")

Example 1 :-
[HTML]<input type="submit" name="Submit" value="Submit" onclick="alert('Hello World'),document.write('Hello World')" />[/HTML]

we can write like this

Example 2 :-
[HTML]<input type="submit" name="Submit" value="Submit" onclick="JavaScript:alert('Hello World'),document.write('Hello World');" />
[/HTML]

or

Example 3 :-
In <head>
[HTML]<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/
function btnClick()
{
alert("Hello World")
document.write("Hello World");
}
/*]]>*/
</script> [/HTML]

in <body>

[HTML]<input type="submit" name="Submit" value="Submit" onclick="btnClick();" />[/HTML]

All three Example will give the same result
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Nov 29th, 2006
0

Re: Java script - wordwrap ?

Click to Expand / Collapse  Quote originally posted by peter_budo ...

[a valid, functional javascript function in an event handler attribute]

IS NOT a JavaScript, it is only action taken once button pressed, which will triget this action. So as it is on its own that code will do nothing
heck, I write huge javascript functions dynamically (on CGI/XSLT pages); directly into onwhatever attributes.

and i've never had any problems.

well that's a lie.

generally lengthly event attributes in HTML should be avoided where possible for managability, but sometimes it's the most simple solution: <body onload="alert({$STATUS});"/> for example, works nicely in XSLT, and the other language I'm using at the moment.
Moderator
Featured Poster
Reputation Points: 522
Solved Threads: 64
Veteran Poster
MattEvans is offline Offline
1,091 posts
since Jul 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in HTML and CSS Forum Timeline: Urgent...Having problem with the following HTML code in IE7
Next Thread in HTML and CSS Forum Timeline: css





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC