GessWurker
asked on
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>
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>
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
also the first change is easy. subsequent cahnges will be much harder to manage
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
ASKER
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
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
ASKER
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).
ASKER
Maybe I should re-post in the asp area.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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