[dancer-users] Getting param name of dynamically named <input> tag
Christian Huldt
christian at solvare.se
Fri Oct 9 22:44:05 BST 2015
Den 2015-10-09 kl. 23:32, skrev Richard Reina:
>
>
> 2015-10-09 16:12 GMT-05:00 Christian Huldt <christian at solvare.se
> <mailto:christian at solvare.se>>:
>
> To me, that seems to be able to add several tags with the same id - I
> think that is harmful...
>
> Den 2015-10-09 kl. 23:02, skrev Richard Reina:
> > I have a input tag in a form:
> >
> > <div class="col-xs-4 col-md-4">
> > <div id="p_scents">
> > <p>
> > <label for="p_scnts"><input type="text"
> id="p_scnt" size="20" name="p_scnt" value="" placeholder="email
> address" /></label>
> > </p>
> > </div>
> > </div>
> >
> >
> > Which gets it's name from the JS function below. However, that
> name I can't figure out. I have tried
> > p_scnt_1 but it comes back undefined. Any ideas what the param
> name would be for each sequentially added item?
> > Here's a working example of the form:
> http://jsfiddle.net/jaredwilli/tzpg4/4/
> >
> >
> > $(function() {
> > var scntDiv = $('#p_scents');
> > var i = $('#p_scents p').size() + 1;
> >
> > $('#addScnt').live('click', function() {
> > $('<p><label for="p_scnts"><input type="text"
> id="p_scnt" size="20" name="p_scnt_' + i +'" value=""
> placeholder="Input Value" /></label> <a href="#"
> id="remScnt">Remove</a></p>').appendTo(scntDiv);
> > i++;
> > return false;
> > });
> >
> > $('#remScnt').live('click', function() {
> > if( i > 2 ) {
> > $(this).parents('p').remove();
> > i--;
> > }
> > return false;
> > });
> > });
>
>
> I don't think it adds the tags with the same name because when I test
> the params the first p_scnt comes through as the first value added. If
> the tags were being added with the same name I would think that either
> 1) they would be string with both values or 2) the last input would
> override the previous input. Since param('p_scnt') equals the first
> value entered neither of those outcomes are occurring.
No, you dealt with the names, but not with the ids. That's my only input
so far.
Isn't there a way to get param as a hash, so you could just use keys to
get what you want?
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x82663443.asc
Type: application/pgp-keys
Size: 1696 bytes
Desc: not available
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20151009/2946efc7/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: OpenPGP digital signature
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20151009/2946efc7/attachment.sig>
More information about the dancer-users
mailing list