onclick text select and also a comment script if possable

monsterm

New Member
Messages
44
Reaction score
0
Points
0
i have 2 text fields and when i click on a text it highlights the whole box but the problem is thast it only highlights 1 box instaed of 2 boxes. heres the javascript im using


HTML:
<html><head><title>(Type a title for your page here)</title>

<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
}
function select_all()
{
var text_val=eval("document.form1.type1");
text_val.focus();
text_val.select();
}

</script>

</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<form name=form1 method=post action='' ''>
<input type="text" name="type" size="70" onClick="select_all();" value="text1">
<p>
<input type="text" name="type1" size="70" onClick="select_all();" value="text2">
</p>
</form>

</body>
</html>

if u wonna try it out the page is http://monstermatt2.pcriot.com/test/

also

if anyone has a script that site viewers can comment on the page without being registerd (like on some sites u have to register to make comments) and only

Name
email
your comment


can u pm me or reply in here thx


(im making a video page)
 

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
You can not use two functions with the same name. The code below should work fine for you.

Code:
<html><head><title>(Type a title for your page here)</title>

<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
}
function select_all_1()
{
var text_val=eval("document.form1.type1");
text_val.focus();
text_val.select();
}

</script>

</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<form name=form1 method=post action='' ''>
<input type="text" name="type" size="70" onClick="select_all(); select_all_1();" value="text1">
<p>
<input type="text" name="type1" size="70" onClick="select_all(); select_all_1();" value="text2">
</p>
</form>

</body>
</html>
 
Last edited:

leafypiggy

Manager of Pens and Office Supplies
Staff member
Messages
3,819
Reaction score
163
Points
63
Code:
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
}
function select_all()
{
var text_val=eval("document.form1.type1");
text_val.focus();
text_val.select();
}

</script>

You declared the function twice. Try this:

Code:
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
var text_val1=eval("document.form1.type1");
text_val1.focus();
text_val1.select();
}


</script>
 
Last edited:

VPmase

New Member
Messages
914
Reaction score
0
Points
0
Code:
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
}
function select_all()
{
var text_val=eval("document.form1.type1");
text_val.focus();
text_val.select();
}

</script>
You declared the function twice. Try this:

Code:
<script type="text/javascript">
function select_all()
{
var text_val=eval("document.form1.type");
text_val.focus();
text_val.select();
var text_val1=eval("document.form1.type1");
text_val1.focus();
text_val1.select();
}


</script>
That script will do the same as having the two functions lol.

Something like this should work and is efficient:
Code:
<html><head><title>(Type a title for your page here)</title>

<script type="text/javascript">
function selectText(b){
switch(b){
case 1:
var text_val = eval("document.form1.type");
text_val.focus();
text_val.select();
break;
case 2:
var text_val=eval("document.form1.type1");
text_val.focus();
text_val.select();
break;
}
}
</script>

</head>
<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<form name="form1" method=post action='' ''>
<input type="text" name="type" size="70" onClick="selectText(1);" value="text1">
<p>
<input type="text" name="type1" size="70" onClick="selectText(2);" value="text2">
</p>
</form>

</body>
</html>
 
Last edited:

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
No need for eval or switches or even the call to focus(). Also, the <p> element isn't structural and the <body> attributes are deprecated; you should replace all of them with styling.

HTML:
<html><head><title>(Type a title for your page here)</title>
<script type="text/javascript">
function selectText(node){
    node.select();
}
</script>
<style type="text/css">
/* replacements for <body> attributes. These values are most likely the same as the
 * browser defaults, so could be dropped entirely with no noticeable effect. 
 */
body {
  background-color: white;
  color: black;
}
a { color: blue; }
a:visited: {color: purple;}
a:active: { color: red; }

/* No need for the <p> element that contained text1. Use style instead. */
form input {
  display: block;
}

</style>
</head>
<body>

  <form name="form1" method=post action=''''>
    <input type="text" name="type" size="70" onClick="selectText(this);" value="text1" />
    <input type="text" name="type1" size="70" onClick="selectText(this);" value="text2" />
  </form>
</body></html>
 
Top