setting the values in a hidden field by appending

Results 1 to 2 of 2

Thread: setting the values in a hidden field by appending

  1. #1
    Join Date
    Dec 1969

    Default setting the values in a hidden field by appending

    Hi,<BR><BR>I&#039;m having a problem setting the values in a hidden field by appending a counter onto a field name as the last character.<BR><BR>I basically need to do this:<BR><BR>"wholeForm.image_x_size_"+ i + ".value" = imageWidth;<BR><BR>Here is the rest of the story:<BR><BR>I need to send hidden fields in this format for each picture:<BR><BR>&#060;input type=hidden name="image_url_1" value=" 128.jpg"&#062;<BR>&#060;input type=hidden name="image_x_size_1" value="1200"&#062;<BR><BR>&#060;input type=hidden name="image_url_2" value=" 134.jpg"&#062;<BR>&#060;input type=hidden name="image_x_size_2" value="1200"&#062;<BR><BR>&#060;input type=hidden name="image_url_3" value=" 141.jpg"&#062;<BR>&#060;input type=hidden name="image_x_size_3" value="1200"&#062;<BR><BR>...etc<BR><BR><BR>And... I have to calculate the photo size in javascript (by finding the orientation of the picture, you know horizontal or vertical):<BR><BR>So I do that and then I put it back into the variables:<BR><BR> wholeForm.image_x_size_1.value = imageWidth;<BR> wholeForm.image_y_size_1.value = imageHeight;<BR><BR>So I need to construct this:<BR><BR>wholeForm.image_x_size_1.value<BR>who leForm.image_x_size_2.value<BR>wholeForm.image_x_s ize_3.value<BR>etc...<BR><BR>but I can&#039;t append on a counter (&#039;i&#039; in this case)<BR><BR>"wholeForm.image_x_size_"+ i + ".value" = imageWidth;<BR><BR>...or using an eval:<BR><BR>eval("wholeForm.image_x_size_"+ i + ".value) = imageWidth;<BR><BR>...I could use an array<BR><BR> for ( i=0 i&#060;numOfPhotos; i++){<BR><BR> "wholeForm.image_x_size_"+ i + ".value" = wholeForm.image_y_size_[i].value;<BR><BR> }<BR><BR>...but run into the same problem of putting the variables into the clubphoto required format:<BR><BR><BR>Any sort of help would be MUCH appreciated!<BR><BR>Phil

  2. #2
    Join Date
    Dec 1969

    Default Actually, you could...

    ...use eval:<BR><BR>eval("wholeForm.image_x_size_"+ i + ".value = " + imageWidth );<BR><BR>But it&#039;s more efficient to do this:<BR><BR> wholeForm.elements["image_x_size_"+i].value = imageWidth;<BR><BR>You can access the elements of any form using the (what else?) "elements" collection. And you can index into that collection either by element number *or* by element name (just like in all JS arrays, of course). <BR><BR>This thus becomes a simple hash-table lookup, whereas if you use eval() the system has to suspend the interpreter, invoke the compiler to compile the to-be-eval&#039;ed test, insert the compiled code into the logic flow, interpret it, remove the compiled code, and finally resume. Probably a thousand times slower.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts