[Javascript] Dynamically create & populate a hidden form fiel d...
Chris Nafziger
CNafziger at sauder.com
Wed Jul 31 16:48:12 CDT 2002
I understand your changes to the function, but it doesn't get rid of the
need to define the hidden field in the html, which is the goal. I'm not
sure what I think about your frame idea with the array of objects yet; I'll
have to consider that further. I'm not really interested in the delimited
string split/parse mechanism; I understand that, and use it in several
places. I don't want to define the hidden field in the html, and in
Whatever.asp, I want to simply be able to say something equivalent to,
albeit in a more elegant fashion:
<%
Value = Request.Form("SBox")
Text = Request.Form("SBoxText")
%>
-----Original Message-----
From: Rodney Myers [mailto:rodney at aflyingstart.net]
Sent: Wednesday, July 31, 2002 5:09 PM
To: javascript at LaTech.edu
Subject: Re: [Javascript] Dynamically create & populate a hidden form
field...
Chris,
I don't know about creating fields on the fly, and ina nexisitng form -
though I
do it all the time by wrting a complete form in another frame.
But if you put all the hidden fields in (and I take it you will have many
selects) :
function GetSBText(eRef) {
var temp = eRef.options[eRef.selectedIndex].text;
var form=eRef.form;
form.elements[eRef.name+'Text'].value = temp;
}
Alternatively, put the select names and data into an array of objects then
onSubmit run these off
EITHER into building a form in another frame
OR creating a delimited string which you can split and parse in ASP after
assigning it to one hidden field.
hth
Rodney
Chris Nafziger wrote:
> Question (regarding code at bottom): How can I modify the GetSBText
> function, so that I can omit the hidden field definition in the html? I
> want to omit this line: <input name="SBoxText" type="hidden">
>
> Goal: In addition to what the function already does, I want it to use the
> reference to take the name of the element ('SBox' in this case), always
> concatenate 'Text' to the name ('SBoxText'), and create & populate a
hidden
> form field with that name. If a selects something, changes their mind and
> selects something else, then it shouldn't attempt to recreate the field,
but
> rather, only populate it.
>
> Reason: The reason I'm wanting to do this, is so the actual text selected
> is also available in the (ASP) Request object on the page it's posting to.
> The reason I chose to use the <select> onchange event rather than the
<form>
> onsubmit event, is because I felt it would be easier to get a truly
generic
> function, that could be used for any <select>, or multiple "<select>s" on
a
> form by simply putting 'onchange="GetSBText(this); return true;"' on each
> select. The reason behind that is because I'm really passing a recordset
to
> a VBScript function that creates the html, as well, so if I want the
> "<option>'s" displayed value to be in the next page's request object, I
can
> simply trigger it on/off by setting a boolean parm to the VBScript
function,
> so it knows whether to include 'onchange="GetSBText(this); return true;"'
> in the html or not.
>
> Again, my question is: How can I modify the GetSBText function, so that I
> can omit the hidden field definition in the html?
>
> <html>
> <head>
> <script LANGUAGE="JavaScript">
> <!--
> function GetSBText(eRef) {
> //
> temp = eRef.options[eRef.selectedIndex].text;
> document.all['SBoxText'].value = temp;
> }
> -->
> </script>
> </head>
> <body>
> <br><br>
> <form action="Whatever.asp" method="post">
> <select name="SBox" onchange="GetSBText(this); return true;">
> <option value="1">One</option>
> <option value="2">Two</option>
> <option value="3">Three</option>
> </select>
> <br><br>
> <input name="SBoxText" type="hidden">
> <input type="submit" value="Go!">
> </form>
> </body>
> </html>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list