views:

137

answers:

3

I'm rather new to HTML programming. I understand the basics of interactive collection of input via forms.

I'd like to collect some data computed by a JavaScript function during execution of a page. Not being able to think of an alternative, I think the way to do that is to enter the function result into a form variable. How do I do that (simple example for a single scalar numeric value, please)?

Forms data is typically a short string. For my problem, I'd like to collect a largish array of results (set of booleans or naturals, size ~~ 1000). Presumably if that's converted to a string (of size several thousand bytes) I can return that string as a forms variable the same way as the scalar answer. Does the size of the string get me into trouble anywhere?

Suggestions?

+1  A: 

There is something out there called jQuery you really need to look at. Among the laundry list of insanely glorious things it does, there is a jQuery Form Plugin that does a lot of this for you. I recommend, if you're starting from scratch, going to the bookstore and picking up JQuery in Action. All you really need to read are the first two chapters. BELIEVE ME, it's totally worth your time.

Dave Markle
Its a shame JQuery is moving so fast and that book is already out of date.
DeletedAccount
Yeah, but it's a great introduction.
Dave Markle
True, true. Sorry I didn't mean to come off like I didn't agree! :o)
DeletedAccount
OK, I'll go look. But is the answer to my basic question really need a (huge) library? I was rather expecting a few lines of HTML and Javascript.
Ira Baxter
jQuery is definitely not huge, all things considered. But here's the thing -- if you don't use something like this, there are a lot of esoteric things in JavaScript which will come and bite you (especially if you are trying to make your project cross-browser). What you thought would be 1 or 2 lines of code become 10 or 20. jQuery brings that back down to a sane level. It's fast, small, cross-browser, well understood, and dead easy to learn.
Dave Markle
A: 

You could try:

document.getElementById('<!--Your form element's id here-->').value('<!--what you want the form value to say -->');

Just run that every time you want to change it.

About getElementById() & More methods on text objects.

Also: Does the size of string matter?

I don't think so, but just to be safe, you could dump the values into a <textarea>, which I believe has unlimited length.

asperous.us
`<textarea>` can be unlimited but the size of the request made to webserver can´t. so, i would take care of the size of string.
Leonel Martins
A: 

I do not see any danger in what you plan to do. I would start with that and not think of alternatives (AJAX) until you are sure the danger is real.

Several thousand bytes is not a lot for a form input. When you said that it is usually a short string, you forgot textareas. They are often quite long, and that is what I use when I send a lot of data to the server.

buti-oxa