Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing Values in a selected combo box

Status
Not open for further replies.

DaveyCrockett

Programmer
Jul 15, 2003
36
US
Hello Everyone,

I have a tricky problem here. I am creating a page that dynamically creates 24 combo boxes with a different name for each (ie.. 11~100~10~10~2,12~200~21~50~2,etc...)

What that means is that I am creating a combo box for each item I want selected. I populate the first number from one table (11) then add the '~' to separate other values retrieved from another table. Below is the sample script.

Code:
<Select Name=&quot;cbo<%= rsMeals(&quot;MENUM&quot;) & rsMeals(&quot;MEItem&quot;) %>&quot; size=&quot;1&quot; ONCHANGE=&quot;HandleChange();&quot;>
	<% rsItems.MoveFirst
	While Not rsItems.EOF				Response.Write &quot;<option value=&quot; & rsItems(&quot;FDID&quot;)  & &quot;~&quot; & _
	rsItems(&quot;FDCalories&quot;) & &quot;~&quot; & rsItems(&quot;FDProteins&quot;) & &quot;~&quot; & _					rsItems(&quot;FDCarbs&quot;) & &quot;~&quot; & rsItems(&quot;FDFats&quot;) & &quot;>&quot; & rsItems(&quot;FDName&quot;) & _		&quot;</option>&quot;		
  rsItems.MoveNext
Wend
%>
</Select>

And it gives me html like this.

<Select Name=&quot;cbo11&quot; size=&quot;1&quot; ONCHANGE=&quot;HandleChange();&quot;>
<option value=70~0~0~0~0>Select An Item…</option>
<option value=15~220~25~18~7>Chocolate Bar</option>
</Select>

What I want to do is parse through in the &quot;HandleChange&quot; script to see:
1. Which combo box was selected?
2. What item in the combo box was selected (first set of digits to the left of the '~')
3. What is the 2nd, 3rd, 4th and 5th numeric values in the &quot;value&quot; attribute of the combo box selected.

With this information, I want it to populate a table to the right of the combo box with these values parsed out.

Is this possible with Javascript? Or should I start learning asp.net? I think it might be able to, but am unsure.. any help would be appreciated.

Thank you all in advance.
 
It is completely possible... You can do just about anything with client-side javascript... especially in IE...

Sorry I don't have time to help you with this but here is a great reference...


Also if you are going to be doing this stuff cross-browser and not just for IE I highly suggest &quot;Dynamic HHTL The Definitive Reference by Danny Goodman&quot;

if not you should be able to find all the ie dom stuff you need from

Good luck...
 
I will look into that suggestion.

Ok. Maybe too much information.. How can I parse the '~' out of the combo.value field.

var ttlValue
var Part1;
var Part2;
var Part3;

ttlValue = parseFloat(document.formname.selectbox1.value);
Part1 = parse(ttlValue,'~')

Will that work??? how can you parse through the values? Sometimes the values are 1 digit, sometimes 2 and even sometimes 3 in length.

Thanks again
 
why parse it first remove it...
ttlValue = document.formname.selectbox1.value.replace(&quot;~/g&quot;,&quot;&quot;);
ttlValue=parseFloat(ttlValue)

Known is handfull, Unknown is worldfull
 
What you have is a string of values delimited by the ~ char.
You can easily split it into an array of the values with (surprisingly) the split() method.

Code:
var strValue = document.formname.selectbox1.value
var valuesArray = strValue.split(&quot;~&quot;)

You now have an array of strings, eg &quot;70&quot; &quot;0&quot; &quot;0&quot; &quot;0&quot; &quot;0&quot; -

:)

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top