add option value to hidden text field on change

Not sure if this can be done, but...

I'd like to add the select option value to the appropriate hidden text value as follows. The action should occur onChange. The option value should be added to the hidden text field that ends with the same number in brackets at the end of the hidden text value.

Again, what I want to do: Add the selected value to the contents of the hidden input field where those contents end with the passed number in brackets. That is, with the first select menu below, onchange I want "addValue(5)" to add the selected value to the hidden input field contents that end with [5]. That would mean that the content:

<input type="hidden" name="itemsRequested" value=" 1. Analysis of freeway accident detection / Corby, Marion J. Saccomanno, F. Frank. 1997 (TA 1001.5 P7 1997) Test Prep. [5] "/>

might become (depending on the selected option)

<input type="hidden" name="itemsRequested" value=" 1. Analysis of freeway accident detection / Corby, Marion J. Saccomanno, F. Frank. 1997 (TA 1001.5 P7 1997) Test Prep. [5] Format: Large Print" />

while

<input type="hidden" name="itemsRequested" value=" 2. Association between cellular telephone calls and motor vehicle collisions / Redelmeier, Donald A. Tibshirani, Robert J. 1997 (TA 427 .P6 R234a 1997) Other. [4] "/>

might become

<input type="hidden" name="itemsRequested" value=" 2. Association between cellular telephone calls and motor vehicle collisions / Redelmeier, Donald A. Tibshirani, Robert J. 1997 (TA 427 .P6 R234a 1997) Other. [4] Format: e-Text "/>

The html:
<form name=form action="">
<select name="format" onChange="addValue(5)">
    <option></option>
    <option value=" Format: Large Print">Large Print
    <option value=" Format: Braille">Braille
    <option value=" Format: Digital Audiotext">Digital Audiotext
    <option value=" Format: e-Text">e-Text
  </select>
<br>
<input type="hidden" name="itemsRequested" value=" 1. Analysis of freeway accident detection / Corby, Marion J. Saccomanno, F. Frank. 1997 (TA 1001.5 P7 1997) Test Prep. [5] "/>
<br>
<select name="format" onChange="addValue(4)">
    <option></option>
    <option value="Large Print">Large Print
    <option value="Braille">Braille
    <option value="Digital Audiotext">Digital Audiotext
    <option value="e-Text">e-Text
  </select>
<input type="hidden" name="itemsRequested" value=" 2. Association between cellular telephone calls and motor vehicle collisions / Redelmeier, Donald A. Tibshirani, Robert J. 1997 (TA 427 .P6 R234a 1997) Other. [4] "/>
</form>
GessWurkerAsked:
Who is Participating?
 
James RodgersWeb Applications DeveloperCommented:
take a look at this, should give you an idea onhow to proceed
http://www.thescripts.com/forum/thread711084.html
0
 
James RodgersWeb Applications DeveloperCommented:
just out of curiosity, why are you doing this, it doesn't seem necessary as when the form is submitted yopu will have the info anyway and can more easily manipulate it on the form processing page than with js before submitting
0
 
James RodgersWeb Applications DeveloperCommented:
also the first change is easy. subsequent cahnges will be much harder to manage
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
James RodgersWeb Applications DeveloperCommented:
all your form fields share the same name, this is not going to work, in order to do it your form elments will need to have unique names, without unique identifiers it cannot be done, you cannot updatye the value for 'itemsRequested' when ther is more than one element with that name, the script will crash
0
 
GessWurkerAuthor Commented:
Jester 48:

Right, I could take care of it on the ASP page... if only I knew how. See the for loops in the ASP page that I'd need to mess with. I guess I'd need to paste to arrays together?

      For each Item in Request("ItemsRequested")
            Mail.Body = Mail.Body & VbCrLf & Item
      NEXT

      Mail.Body       = Mail.Body & VbCrLf & VbCrLf & "The following formats were requested" & VbCrLf

      For each Item in Request("Format")
            Mail.Body = Mail.Body & VbCrLf & Item
      NEXT
0
 
GessWurkerAuthor Commented:
Jester 48: Yes, there are multiple fields with the same name. However, I could certainly give them unique IDs. The ASP script I'm using to email the form data handles multiple fields with the same name via for loops (as you can see in my previous message).
0
 
GessWurkerAuthor Commented:
Maybe I should re-post in the asp area.
0
 
b0lsc0ttIT ManagerCommented:
Do you still need help with this?  If you want it done with the onchange event the ASP isn't the answer.  It is Javascript you need.

Although I would rather see you have unique names for the fields (and you may have issues because of this) there could be a way to do this in Javascript.  Let me know if you still need help and I will work on the script to use.

bol
0
 
GessWurkerAuthor Commented:
In fact, I've gotten some help on the asp side. I'm combining arrays quite effectively (thanks to an expert named CCongdon). Unique fields names would of course be better, but in my particular context, they're not really feasible. It's too long of a story or I'd explain further. Anyway, now my biggest issue is to re-do all the validation on my request form. More on that later. Stay tuned. I'm going to close out this question
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.