Solved

add option value to hidden text field on change

Posted on 2007-11-16
9
891 Views
Last Modified: 2012-05-05
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>
0
Comment
Question by:GessWurker
  • 4
  • 4
9 Comments
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
also the first change is easy. subsequent cahnges will be much harder to manage
0
 
LVL 25

Expert Comment

by:James Rodgers
Comment Utility
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
 

Author Comment

by:GessWurker
Comment Utility
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:GessWurker
Comment Utility
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
 

Author Comment

by:GessWurker
Comment Utility
Maybe I should re-post in the asp area.
0
 
LVL 25

Accepted Solution

by:
James Rodgers earned 500 total points
Comment Utility
take a look at this, should give you an idea onhow to proceed
http://www.thescripts.com/forum/thread711084.html
0
 
LVL 54

Expert Comment

by:b0lsc0tt
Comment Utility
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
 

Author Comment

by:GessWurker
Comment Utility
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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now