...

View Full Version : Inserting text on click



Phalanxer
06-28-2012, 10:53 AM
I am trying to insert text into an INPUT field when I click the button "1".

I have used this code, but its not working. Can anyone see what I have done wrong?



<INPUT type="button" value="1" onclick="document.forms["form"]["number"].value .= "1"">

abduraooft
06-28-2012, 11:24 AM
onclick="document.forms["form"]["number"].value .= '1'"

Phalanxer
06-28-2012, 11:52 AM
Thanks for that! ... Its been one of thoughs days!!

I also changed the double quotes to quotes, as this was causing an error too, now my error console reports the following error:



Error: missing name after . operator
Source Code:
document.forms['form']['number'].value .= '1'


I'm not quite sure what to make of this. Do you have any idea what it means?

Philip M
06-28-2012, 11:55 AM
I'm not quite sure what to make of this. Do you have any idea what it means?

It means a typo - should be

onclick="document.forms['form']['number'].value = '1'";

'1' is a string value. 1 is a number.

It is not a good idea to assign the name number to a form field. Use num or something.

You have now spotted that you were using double quotes within double quotes.

Its been one of thoughs days!!

Phalanxer
06-28-2012, 12:02 PM
I can't use:


onclick="document.forms['form']['number'].value = '1'"

... because if I press my virtual buttons '1' '2' and '3', then the INPUT number is going to be '3', where I need it '123', hence why I tried using .=. :)

Phalanxer
06-28-2012, 12:12 PM
Ah, I just needed to change .= to +=. :)

Solved.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum