Search the archives!
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Javascript] Dynamically create & populate a hidden form field...
- From: javascript@xxxxxxxxxx (Josiah Gordon)
- Subject: [Javascript] Dynamically create & populate a hidden form field...
- Date: Wed, 31 Jul 2002 14:20:36 -0700
Chris, That's my thought too. I've done something similar by always including a hidden field for additional arguments that the server needs and just appending [name,key] pairs and parsing everything out server-side. This way you can have any number of unknown elements and forms on the page add data with little additional overhead on the querystring (with the implicit assumption that no entry equates to NULL). --Josiah Gordon -----Original Message----- From: javascript-admin@xxxxxxxxxx [mailto:javascript-admin@xxxxxxxxxx]On Behalf Of Rodney Myers Sent: Wednesday, July 31, 2002 2: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
- References:
- [Javascript] Dynamically create & populate a hidden form field...
- From: Rodney Myers
- [Javascript] Dynamically create & populate a hidden form field...
- Prev by Date: [Javascript] Dynamically create & populate a hidden form field...
- Next by Date: [Javascript] Dynamically create & populate a hidden form fiel d...
- Previous by thread: [Javascript] Dynamically create & populate a hidden form field...
- Next by thread: [Javascript] Dynamically create & populate a hidden form fiel d...
- Index(es):