Wrox Programmer Forums
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 10th, 2004, 08:36 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Parsing a form menu

I need to parse a menu result value into two other input fields. The values are comma separated.

Here is the example:

<form action="" method="get">
  <p>Vendor Name: <input name="VendorName" type="text">
    <br>Vendor Number: <input name="VendorNumber" type="text"><br>
    List of Current Vendors:
            <select name="select">
              <option value="Apple,0000">Apple,0000</option>
              <option value="APPLE COMPUTER INC,2956">APPLE COMPUTER INC,2956</option>
              <option value="APPLE COMPUTER INC,2957">APPLE COMPUTER INC,2957 </option>
    </select></p></form>

Edward C. Sheard, CCP
Project Leader-Web Services
Madison Area Technical College
3550 Anderson Street
Madison, WI&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;53704-2599
Phone:&nbsp;&nbsp;(608) 246-6129&nbsp;&nbsp;
FAX:&nbsp;&nbsp;(608) 246-6329
Web:&nbsp;&nbsp;http://matcmadison.edu
Department of Educational Technology and Services (DoETS)
 
Old March 10th, 2004, 08:51 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Use split method of String.prototype which creates an array:
Code:
function showData(Listbox)
{
  var iIndex = Listbox.selectedIndex
  if (iIndex == -1) return;  
  var sValue = Listbox.options[iIndex].value;
  var arrData = sValue.split(",");
  alert(arrData[0]);
  alert(arrData[1]); 
}
Add onchange="showData(this);" to the select tag. You'll need to be sure that the value cannot contain any commas as data. Better if you used something unlikely to appear in text such as pipe character | if possible. Better still, have an array containing the data and have the value as the relevant index into this array.



--

Joe
 
Old March 11th, 2004, 09:35 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Out Standing !!!

Thank you joefawcett :D

I took your suggestion and used the pipe. It works great!

Edward C. Sheard, CCP
Project Leader-Web Services
Madison Area Technical College
3550 Anderson Street
Madison, WI 53704-2599
Phone: (608) 246-6129
FAX: (608) 246-6329
Web: http://matcmadison.edu
Department of Educational Technology and Services (DoETS)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT for parsing XHTML Form shahbhat XSLT 6 August 26th, 2008 06:22 PM
Pure CSS Menu Showing Behind Form Fields in IE kwilliams CSS Cascading Style Sheets 10 November 19th, 2007 10:25 AM
attaching form to menu item kscase Visual Basic 2005 Basics 4 January 19th, 2007 12:07 PM
new entry for drop-down menu and open form avigiano Access 4 September 27th, 2006 07:44 AM
checkbox and the drop down menu in update form phudong3da Dreamweaver (all versions) 3 May 4th, 2005 01:55 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.