Gossamer Forum
Home : General : Internet Technologies :

Seeking: Javascript for Centering Text in textbox

Quote Reply
Seeking: Javascript for Centering Text in textbox
Hi All

I'm looking for some javascript to center text that is submitted through a form.

The script needs to be able to count characters, make a calculation for centering against a MAXLENGTH value for each field, and then insert the correct number of 'spaces' in the front of the submitted text.

It would also be super helpful if the script could handle multiple text boxes (up to 12) as a group (each text box would have its own maxlength value for the centering calculation) so that a visitor could simply fill in all 12 text boxes and then click a button that says "Center Text" and then the script makes all the calculations and auto-adds spaces in front of the text and then displays the results in the form.

It would also work on a line-by-line basis, too. Each textbox could simply have a checkbox ("Center?") if that would make things easier. Then, maybe I could get a "Check All" button to make it easy for someone to check off centering for all their text boxes.

The script should allow admin to determine how the "center" is determined. What I mean is, for example, if you have a maxlength of 16 and a visitor enters a 6 character word, then the centering action would just add 5 spaces to the front of the word. However, if the maxlength is 15 characters, then admin has to decide which side to favor - should it be 5 spaces or 4 in front of the word? That value admin could tweak in the code.

The script should also be able to strip any stray spaces in the front and back of the submitted word before calculating the centering. This way, you don't have any inadvertent spaces in the front or back messing up the centering of the actual text.

The script would be combined with other scripts in the form - including a fair amout of validation code. OnBlur, OnChange for each text box. OnSubmit for the form. OnClick in the form button.

There would also be multiple forms on the same page.

The "Center Text" would be optional. It should be a separate button that could be clicked if desired. Otherwise, the data in the form stays unchanged (in orientation). (As mentioned above, it could also be that each textbox has its own checkbox to do one textbox at a time and that maybe I could get a CheckAll type of button to get all lines to center as a group).

If you've gotten this far in my long-winded description, I really appreciate it Smile Smile

Do you think the above type of javascript is possible? Available somewhere? (I'm searching around)

Thanks very much Smile

------------------------------------------