dynamically set textboxes

  • Thread starter Ben Dover - Mental Patient 0057
  • Start date
B

Ben Dover - Mental Patient 0057

i want to be able to dynamically set different text boxes depending on
the button pressed.


i was hoping obj() can "become" object "aaa" or "bbb", but it's not
working.

function clearBox(inputobject) {
var obj=(inputobject);
document.main.ojb().value="hello";
document.main.aaa.focus();
}


----------------
<form name="main">
<input type="text" value="aaa" name="boxaaa">
<input type="text" value="bbb" name="boxbbb">
<input type="button" value="clickme" onclick="clearBox(aaa)">
<input type="button" value="clickme" onclick="clearBox(bbb)">
</form>
 
L

Lasse Reichstein Nielsen

Ben Dover - Mental Patient 0057 said:
i want to be able to dynamically set different text boxes depending on
the button pressed.
i was hoping obj() can "become" object "aaa" or "bbb", but it's not
working.

function clearBox(inputobject) {
var obj=(inputobject);
document.main.ojb().value="hello";

From the FAQ <URL:http://jibbering.com/faq/#FAQ4_39>

document.forms['main'].elements[inputobject].value="hello";

(I prefer to always use the forms and elements collections)

This also requires that the remaining code is correct :
<input type="text" value="aaa" name="boxaaa">
<input type="text" value="bbb" name="boxbbb">
<input type="button" value="clickme" onclick="clearBox(aaa)">
onclick="clearBox('aaa')"
You want to send a string, not the value of the possibly non-existing
global variable called "aaa".
<input type="button" value="clickme" onclick="clearBox(bbb)">

Ditto here.

/L
 
B

Ben Dover - Mental Patient 0057

just want to share with everyone what I put together:
in the head:

function clearBox(inputobject) {
var obj=(inputobject);
document.main[inputobject].value="";
document.main[inputobject].focus();
}


in the body:
<form name="main" >
<INPUT TYPE="TEXT" VALUE="helloworld" NAME="login">
<a href="#" onclick="clearBox('login');">clear login</a>

<INPUT TYPE="TEXT" VALUE="helloworld" NAME="password">
<a href="#" onclick="clearBox('password');">clear password</a>

etc...
</form>


have fun folks!
Ben Dover - Mental Patient 0057 said:
i want to be able to dynamically set different text boxes depending on
the button pressed.
i was hoping obj() can "become" object "aaa" or "bbb", but it's not
working.

function clearBox(inputobject) {
var obj=(inputobject);
document.main.ojb().value="hello";

From the FAQ <URL:http://jibbering.com/faq/#FAQ4_39>

document.forms['main'].elements[inputobject].value="hello";

(I prefer to always use the forms and elements collections)

This also requires that the remaining code is correct :
<input type="text" value="aaa" name="boxaaa">
<input type="text" value="bbb" name="boxbbb">
<input type="button" value="clickme" onclick="clearBox(aaa)">
onclick="clearBox('aaa')"
You want to send a string, not the value of the possibly non-existing
global variable called "aaa".
<input type="button" value="clickme" onclick="clearBox(bbb)">

Ditto here.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top