Jump to content

Increment in field name


drisate

Recommended Posts

Hey guys i have a form that auto generates filds by a click on a botton if the user needs them. I normaly use an array in the field name to retrive the results ... but in this case i can't. The part auto generated is a WYSIWYG box and when i add the [] to the field name it breaks some code because it uses the name as i typed it into other parts.

 

FAIL: id="texte[]___Config"

FAIL: id="texte[]___Frame"

FAIL: src="editor/fckeditor.html?InstanceName=texte[]&Toolbar=Basic"

 

So i was wandering if it would be possible to get som helpp to figure out how to use the auto increment number of the generated field. Heres my coding:

 

<script type="text/javascript" src="http://patrick.cameleonmedia.com/reno/administration/uploads.js"></script>

<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table12">
<tr>
	<td>
	<div id="attachments" class="container"><a id="addupload" href="javascript:addUpload(19, 'desc', 'file')">Add</a></div>
	</td>
</tr>
</table>

<span id="attachmentmarker"></span>
<div id="attachment" class="attachment" style="display:none">
<hr>
<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table12">
	<tr>
		<td><textarea rows="13" name="texte[]" cols="61"></textarea></td>
	</tr>
</table>
</div>

<table border="0" cellpadding="3" cellspacing="3" width="100%" id="table3">
<tr>
	<td align="center"><input type="submit" value="Envoyer" name="B1"></td>
</tr>
</table>

 

In this exemple ia m using a normal textarea because the WYSIWYG code would be to big for nothing.

 

I need to replace name="texte[]" by name="texte_5" or what ever number the auto increment is at.

Link to comment
Share on other sites

I think I understand you, but not totally. But, if you have multiple fields with the same name set as an array (i.e. fieldName[]) there is an easy enough way to reference them in JavaScript. When there are fields with the same name they are also an array within the javascript.

 

In PHP the fields with the name "fieldName" would be referenced as an array in PHP as $_POST['fieldName']. However, in JavaScript, the array index includes the name WITH the brackets.

 

document.form.elements['fieldName[]'] is the array of those field objects and document.form.elements['fieldName[]'][0] would be the first field object. Should be no problem referencing the fields you need accordingly

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.