469,312 Members | 2,503 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

dynamically set textboxes

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>
Jul 20 '05 #1
2 3682
Ben Dover - Mental Patient 0057 <Be*******@psychiatric-center.Bellevue-Hospital.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
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!

Lasse Reichstein Nielsen wrote:

Ben Dover - Mental Patient 0057 <Be*******@psychiatric-center.Bellevue-Hospital.com> writes:
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Briand | last post: by
3 posts views Thread by Egbert Nierop \(MVP for IIS\) | last post: by
5 posts views Thread by Will Lastname | last post: by
9 posts views Thread by netasp | last post: by
6 posts views Thread by Bjorn Sagbakken | last post: by
5 posts views Thread by Chris | last post: by
reply views Thread by rvdnieuwenhuizen | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.