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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Virtual Keyboard"

Status
Not open for further replies.

DigitalBoy

Programmer
Oct 11, 2000
87
US
I have the following code that places characters in a text area when buttons are clicked:

<BODY>

<center>
<form>
<input type=text name=amount value=&quot;A&quot;>
<input type=button value=&quot;up&quot; onClick=&quot;javascript:this.form.amount.value='A';&quot;>
<input type=button value=&quot;down&quot; onClick=&quot;javascript:this.form.amount.value='B';&quot;>
</form>
</center>


My question is: How do I code a button for &quot;space&quot;? Meaning, how do I code a button to tell the cursor to move one position right of it's current position?


- DB



dgtlby@excite.com
Administrator

UBB Developers Network

 
DB,

I made some small changes so that it would make sense to me:


<form>
<input type=text name=amount value=&quot;A&quot;>
<input type=button value=&quot;up&quot; onClick=&quot;javascript:this.form.amount.value += 'A';&quot;>
<input type=button value=&quot;down&quot; onClick=&quot;javascript:this.form.amount.value += 'B';&quot;>
<input type=button
value=&quot;space&quot;
onClick=&quot;javascript:this.form.amount.value += ' ';&quot;>
</form>


Hope this helps
-pete
 
DB,

palbano's soloution is correct. just so you know, the changes he made were:

<input type=button value=up onclick=&quot;javascript:this.form.amount.value += 'A';&quot;>

and the same was done for the second button
make sure to take this out if you don't want to add the letter. theEclipse
eclipse_web@hotmail.com
**\\||It was recently discovered that research causes cancer in rats||//**
 
You know, I almost forgot. I tried to modify the code to create a &quot;backspace&quot; button by using something like:

<input type=button value=backspace onClick=&quot;javascript:this.form.amount.value.length--;>

But I didn't have any luck. Any suggestions?

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
This worked for me in NN4.

<input type=button value=backspace onClick=&quot;javascript:this.form.amount.value=this.form.amount.value.substr(0,this.form.amount.value.length-1);&quot;>

Hope this helps.
daban
 
You know, I had one more question: How do I attach this to an anchor tag? For example, let's say I want to use images or text for my keyboard. I would need to incorporate the javascript in an anchor tag. I tried putting the code in the href tag, but I'm not getting positive results.

Any ideas?

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
if you reference this.form of an 'A' tag, more than likeyl, it will be undefined... you'll have to use a full reference to the form here instead:

document.formname.amount.value jared@aauser.com
 
<a href=# onclick=&quot;javascript:callforyourcode()&quot;>
 
Jaredn,

I tried that. What it did instead of adding to the value in &quot;amount&quot; is it refreshed the page with an &quot;A&quot;.

Iza, I'm OK up to that point, now I just need the rest.

The good news is that I just went out and bought a new IDG book on Javascript, so in a month or so, I will be the one answering questions.

- DB

dgtlby@excite.com
Administrator

UBB Developers Network

 
what do you mean, &quot;the rest&quot; ???
 
Ok, I just tried the following:


<a href=# onclick=&quot;javascript:this.form.amount.value+='A';&quot; name=&quot;button&quot;>A</a>

I know I must be missing something big here, but it still doesn't work. It keeps telling me that this.form.amount is null or not an object. However the following code works perfectly:

<input type=button value=&quot;A&quot; onClick=&quot;javascript:this.form.amount.value+='A';&quot; name=&quot;button&quot;>

What gives?


- DB
dgtlby@excite.com
Administrator

UBB Developers Network

 
this is refering to your link. try using the full path, like document.form adam@aauser.com
 
well, what you should do is:

<a href=# onclick=&quot;javascript:alert(document);&quot; name=&quot;button&quot;>A</a>

it should say object.

then try:

alert(document.form);
alert(document.form.amount)
alert(document.form.amount.value)

till it gives you an error. then you know where your error is, and you can try to fix it.

adam@aauser.com
 
it was just because of the this
in the a href it was referring to the A tag element
in the input tag it was reffering to the document containing the form
sometimes it's weird, that's why i'm also often using luciddream alert method !
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top