Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

input box

Status
Not open for further replies.

filipel

Programmer
Aug 13, 2007
42
PT
How can i make a input text box multiline like a memo when i click on a button?
 
yes but how to assign that to a onclick event?
 
Hi

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/strict.dtd">[/URL]
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title></title>
<style type="text/css">
input#in1line,textarea#inxline {
  width: 400px;
}
textarea#inxline {
  display: none;
}
</style>
<script type="text/javascript">
function ch()
{
  var in1=document.getElementById('in1line')
  var inx=document.getElementById('inxline')
  var inc=document.getElementById('inch')
  var ch2=in1.style.display=='none'
  in1.style.display=ch2?'inline':'none'
  inx.style.display=ch2?'none':'inline'
  if (ch2) in1.value=inx.value; else inx.value=in1.value
  inc.value='Change to '+(ch2?'X':1)+' lines'
}
</script>
</head>
<body>
<form action="">
<p>
<input type="text" name="in1line" id="in1line">
<textarea name="inxline" id="inxline" cols="40" rows="5"></textarea>
<input type="button" id="inch" value="Change to X lines" onclick="ch()">
</p>
</form>
</body>
</html>

Feherke.
 
i have tried to put the javascript code in an external file but i get error on page always.

I have:

<script src="funcoes.js" </script>
 
lol.Error on page on the bottom of ie status bar
 
i tested with the following code and it is the same:

opcoes.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<html xmlns="<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script src="funcoes.js" type="text/javascript"></script>
</head>

<body>
<form>
<input type="button" onclick="as();" />
</form>
</body>
</html>


and funcoes.js on the same directory:

function as(){
alert("hello");

}
 
Filipel,

In order for anyone to help you have to help us.... what is the error. I take it you have IE.. click on the error icon and it will alert with the error type.
 
Hi

Then probably the [tt]getElementById()[/tt] returns [tt]null[/tt]. Well, nothing unusual given your HTML ( and supposing that you try to use the code I posted ) :
Code:
<input type="button" onclick="as();"  />
Note that :
[ul]
[li]I added [tt]id[/tt]s to the elements[/li]
[li]the [tt]id[/tt]s must be consistent across HTML, CSS and JavaScript[/li]
[li]I added the [tt]textarea[/tt] too at design time[/li]
[/ul]

Feherke.
 
Hi

With the risk of starting a flame, FireFox. Especially if is equipped with extensions from the Web and Developer Tools category, for example :
[ul]
[li]FireBug[/li]
[li]Web Developer[/li]
[li]LiveHTTPHeaders[/li]
[li]Html Validator[/li]
[li]View Source Chart[/li]
[li]JSView[/li]
[/ul]
But anyway, the important is the concept. Mozillas are letting you know what happens, without beatifying the $*!* with "user friendly" things.

Feherke.
 
i moved the javascript code of feherke to the funcoes.js and put opcoes.php:

<script src="funcoes.js" type="text/javascript"></script>
and
in firefox error console i get "ch is not defined
 
Hi

Well, that is certainly more than Explorer's quite generic error message.

But the problem is with our imagination. Honestly, I can not imagine what have you done with that poor code... ;-)

Could you put it somewhere publicly accessible ? We need to see the source too.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top