close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Populating text fields from dropdown

Thread began 9/27/2012 5:45 pm by rogersds267040 | Last modified 3/30/2015 12:29 pm by rogersds267040 | 6157 views | 20 replies


Assign values from an array to hidden form elements...

Hi Jason:

I'm trying to do something similar to this so that when the user selects an item in the select list, it's loaded into an array that is then split and each value is in turn passed to it's respective hidden element. This allows me to do the following:

1. Send an email to a specific person in our organization based on the selected index
2. Store the selected index as an ID value so we know what element was selected
3. Store the selected index as a subject for our email, and store that subject in our database.

I've adapted the above code for my form as follows:

JavaScript on menu include file:
<script type="text/javascript">
function setContactData(opts) {
var optArray = new Array;
optArray = opts.split(",");
var contactForm = document.contactform;
var ContactField = contactForm.contactAddress;
var DepartmentNameField = contactForm.deptName;
var DepartmentIDField = contactForm.deptID;
DepartmentIDField.value = optArray[0];
DepartmentNameField.value = optArray[1];
ContactField.value = optArray[2];

Form on Contact section of menu:

<form method="post" action="contact.php" name="contactform" id="contactform">
<legend>Please fill out this form to contact us</legend>
<label for="name" accesskey="U"><span class="required">*</span> Your Name</label>
<input name="name" type="text" id="name" size="40" value="" />
<br />
<label for="email" accesskey="E"><span class="required">*</span> Email</label>
<input name="email" type="text" id="email" size="40" value="" />
<br />
<label for="phone" accesskey="P"><span class="required">*</span> Phone</label>
<input name="phone" type="text" id="phone" size="40" onClick="SelectAll('phone');" value="(###) ###-####" />
<br />
<label for="subject" accesskey="S">Subject</label>
<select name="subject" id="subject" onchange="setContactData(document.contactform.subject[document.contactform.subjectselectedIndex].value)">
<option value="1,Advocacy,">Advocacy</option>
<option value="2,AT,">Assistive Technology</option>
<option value="3,CDS,">CDS Question</option>
<option value="4,CLASS,">CLASS Question</option>
<option value="5,General," selected>General Question</option>
<option value="6,Donations,">Donations</option>
<option value="7,Edu,">Education</option>
<option value="8,Employment,">Employment</option>
<option value="9,Events,">Events</option>
<option value="10,HCS,">HCS Question</option>
<option value="11,IMPACT,">Adult Day Program</option>
<option value="12,News,">Newsletter</option>
<option value="13,Nurse,">Nursing Services</option>
<option value="14,HCSResSvcs,">HCS Residential Services</option>
<option value="15,ICFResSvcs,">HCS Residential Services</option>
<option value="16,TechInitive,">Tech Initiative</option>
<option value="17,Therapy,">Therapy Services</option>
<option value="18,TXHmL,">TXHmL Question</option>
<option value="19,Vol,">Volunteer</option>

<br />
<label for="comments" accesskey="C"><span class="required">*</span>Message:</label>
<textarea name="comments" cols="40" rows="3" id="comments" style="width: 350px;"></textarea>

<p><span class="required">*</span> Are you human?</p>

<label for="verify" accesskey="V">&nbsp;&nbsp;&nbsp;3 + 1 =</label>
<input name="verify" type="text" id="verify" size="4" value="" style="width: 30px;" /><br /><br />

<input type="hidden" name="pgSrc" id="pgSrc" value="5" />
<input type="hidden" name="regDate" id="regDate" value="<?php echo(date("Y-m-d H:i:s")); ?>" />
<input type="hidden" name="deptID" id="deptID" value="" />
<input type="hidden" name="deptName" id="deptName" value="" />
<input type="hidden" name="contactAddress" id="contactAddress" value="" />

<input type="submit" class="submit" id="submit" value="Submit" />



When I test using <?php var_dump(); ?> I get the following error message:
Warning: var_dump() expects at least 1 parameter, 0 given in <path to script page>.../contact.php on line 4

Checking the data that gets inserted to the database, it appears that the value passed in the onChange() is not getting split and loaded into the form elements as expected. Any thoughts or pointers would be most appreciated.


p.s. any pointers on how to pull the email address based on the selected index without exposing it on the client side would be appreciated. Perhaps there is an example of how to pull it from a recordset to populate the hidden element based on the selected index like you do in Dynamic Dropdowns.

Thanks for all you do!

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...