Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Dynamically create & populate a hidden form fiel d...
- From: javascript@xxxxxxxxxx (Chris Nafziger)
- Subject: [Javascript] Dynamically create & populate a hidden form fiel d...
- Date: Wed, 31 Jul 2002 18:58:06 -0400
No, I don't want to append them to the querystring; I want to be able to access the values from the Request.Form collection (I'm aware of the Request.QueryString collection), without defining the hidden fields in the previous page's html. Assigning a value to a form element is simple, so I would think creating a new element wouldn't be that big of a deal. There has to be some way to add new form elements using JavaScript! Isn't there? -----Original Message----- From: Josiah Gordon [mailto:jgordon@xxxxxxxxxxxxxx] Sent: Wednesday, July 31, 2002 6:27 PM To: javascript@xxxxxxxxxx Subject: RE: [Javascript] Dynamically create & populate a hidden form field... I think I see what you are going for. How about appending the values onto the querysting onSubmit()? Instead of: <% Value = Request.Form("SBox") Text = Request.Form("SBoxText") %> You have: <% Value = Request.QueryString("SBox") Text = Request.QueryString("SBoxText") %> Does that do it? --Josiah Gordon -----Original Message----- From: javascript-admin@xxxxxxxxxx [mailto:javascript-admin@xxxxxxxxxx]On Behalf Of Chris Nafziger Sent: Wednesday, July 31, 2002 2:48 PM To: 'javascript@xxxxxxxxxx' Subject: RE: [Javascript] Dynamically create & populate a hidden form field... 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@xxxxxxxxxxxxxxxx] Sent: Wednesday, July 31, 2002 5:09 PM To: javascript@xxxxxxxxxx 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@xxxxxxxxxx > https://lists.LaTech.edu/mailman/listinfo/javascript _______________________________________________ Javascript mailing list Javascript@xxxxxxxxxx https://lists.LaTech.edu/mailman/listinfo/javascript _______________________________________________ Javascript mailing list Javascript@xxxxxxxxxx https://lists.LaTech.edu/mailman/listinfo/javascript _______________________________________________ Javascript mailing list Javascript@xxxxxxxxxx https://lists.LaTech.edu/mailman/listinfo/javascript
- Prev by Date: [Javascript] Dynamically create & populate a hidden form field...
- Next by Date: FW: [Javascript] Dynamically create & populate a hidden form fiel d...
- Previous by thread: [Javascript] Dynamically create & populate a hidden form field...
- Next by thread: FW: [Javascript] Dynamically create & populate a hidden form fiel d...
- Index(es):