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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passed Form Values

Status
Not open for further replies.

westcoaststyle

Programmer
Oct 15, 2001
81
US
I'm using an array to populate a drop menu depending on what is selected from the previous drop menu.

The problem that I'm having is that some of the data that I need to pass is either "0000" (zeros) or "0123" (zero in front). What is happening is when I submit the form, the zeros are being dropped when they are passed to the next page. I am using these values to query a database so they must be exactly like what is stored in the database tables. Is it possible to keep these values exact when pressing submit?

Thanks!!
 
If you are using those values only as strings, I don't know why they would be dropping leading zeros. Can you post some example code?
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
yes, gladly

__________________________
<script language=&quot;Javascript&quot;>

Date = new Array(
new Array(
new Array(&quot;0000&quot;, 0000),
new Array(&quot;0217&quot;, 0217),
new Array(&quot;0229&quot;, 0229),
new Array(&quot;0242&quot;, 0242),
new Array(&quot;0244&quot;, 0244),
new Array(&quot;0255&quot;, 0255),
new Array(&quot;0272&quot;, 0272),
new Array(&quot;0273&quot;, 0273),
new Array(&quot;0286&quot;, 0286),
new Array(&quot;0299&quot;, 0299),
new Array(&quot;0300&quot;, 0300)
),
new Array(
new Array(&quot;0000&quot;, 0000),
new Array(&quot;1201&quot;, 1201),
new Array(&quot;1215&quot;, 1215),
new Array(&quot;1273&quot;, 1273)
)
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[0]);
if (itemArray[1] != null) {
selectCtrl.options[j].value = itemArray[1];
}
j++;
}
selectCtrl.options[0].selected = true;
}
}

</script>
</head>
<body>
<body>
<center>
<form method=&quot;post&quot; target=&quot;_blank&quot;>
Query by <select name=&quot;date_type&quot;
onChange=&quot;fillSelectFromArray(this.form.date, ((this.selectedIndex == -1) ? null
: Date[this.selectedIndex-1]));&quot;>
<option value=&quot;-1&quot;>Select Date Type</option>
<option value=&quot;eff_date&quot;>Effective Date</option>
<option value=&quot;post_date&quot;>Post Date</option>
</select> is
<select name=&quot;date&quot; SIZE=&quot;1&quot;>
<option></option>
<option></option>
</select>
<p>
</p>
<input type=&quot;button&quot; name=&quot;sub1&quot; value=&quot;XML&quot; onClick=&quot;checkaction(this.form,0)&quot;>
</input>
  
<input type=&quot;button&quot; name=&quot;sub2&quot; value=&quot;HTML&quot; onClick=&quot;checkaction(this.form,1)&quot;
></input>
</form></center>
</body>
</html>
 
Want to know why your code turned italic halfway thru? I'll bet $20 (or the equivalent in euros) that you have a
Code:
[i]
subscript in there. When you post code, either turn off TGML (uncheck the &quot;Process TGML&quot; box above the &quot;Submit Post&quot; button) or surround your code with [ code ] and [ /code ] tags (without the spacing). The
Code:
[i]
subscript is interpreted as a TGML italics tag.

Even with the missing subscripts, I can guess that your problem probably has something to do with the fact that your arrays contain both string and numeric values, and you're probably using the numeric value when you want to use the string value. Numeric values will always have leading zeroes stripped off.

If that doesn't help find the problem, try reposting without TGML or with the code tags. Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
here is what i saw:

1. you use date for naming of your array and form element
~ use different names
~ try to avoid of using reserved words to name your own elemants/functions/methods/objects, & date is a reserved word, i guess..

2. may be you should try to use structures instead of arrays? (you see, with your organization you can access &quot;0000&quot; this way: Date[0][0][0], its hard to hold all these indexes in head.. (at least for me))

i mean something like

var _Date={

_first_ : {
elem1 : {
stringValue : &quot;0000&quot;,
numValue : 0000
},
elem2 : {
stringValue : &quot;0217&quot;,
numValue : 0217
}
}

}

//but the numeric values would still be truncated:

alert(_Date._first_.elem1.stringValue+&quot; &quot;+_Date._first_.elem1.numValue)
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top