Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

add option value to hidden text field on change

Posted on 2007-11-16
9
Medium Priority
?
902 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 25

Expert Comment

by:James Rodgers
ID: 20300632
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
ID: 20300647
also the first change is easy. subsequent cahnges will be much harder to manage
0
 
LVL 25

Expert Comment

by:James Rodgers
ID: 20300675
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:GessWurker
ID: 20300698
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
 

Author Comment

by:GessWurker
ID: 20300718
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
ID: 20300805
Maybe I should re-post in the asp area.
0
 
LVL 25

Accepted Solution

by:
James Rodgers earned 2000 total points
ID: 20300905
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
ID: 20302129
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
ID: 20302167
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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
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…

609 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