/    Sign up×
Community /Pin to ProfileBookmark

Can I set an array as "hidden"?

I want to set an array as hidden and then use post method to pass the vaules in the array to the PHP. But it doesn’t work. My codes are:

[CODE]
<form name=”Service” onsubmit=”javascript:return validate_port()”
action=”submit.php?state=<?php echo($instance)?>&section=Services” method=”post”>
<input type=”hidden” name=”service_hide[]” value=””>

<table width=”100%”>
<tr id=”service_button”>

<td align=”right”>
<input type=”button” value=”Add” class=”button1″ onclick=”addService()” >
</td>

<td align=”center”>
<input type=”submit” value=”Save” class=”button1″>
</td>

<td>
<input type=”submit” value=”Delete” class=”button1″ onclick=”setAction(this)”>
</td>

</tr>
</table>
</form>
[/CODE]

The function of addService() is defined as follows:

[CODE]
function addService()
{
document.Service.service_hide[0].value = “0”;
}[/CODE]

When I press the “Add” button, nothing happens. It seems that there is a syntax error, but I don’t know where is the problem.

Can anyone please help me about that? Thanks in advance!

Rui

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — There aren't any form elements named "service_hide". You can't mix syntax like that.

You should concatenate the array and assign it to the value of that hidden input element.
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 18.2005 — Thanks, Kravvitz. So, you mean that I should use like:

[CODE]<input type="hidden" name="service_hide" >[/CODE]

right? The problem is, I actually need an array to save some values input from the GUI (these values are the input of a new row created by javascript) and I want to send them through post method to another php file. So, do you know how I can do that?

Thank you very much!

Rui
Copy linkTweet thisAlerts:
@KravvitzOct 18.2005 — Yes, the code for the element should look like that.

Like I said, you should concatenate them. Make sure to use a character or a few characters that won't appear in the array items.
Copy linkTweet thisAlerts:
@reinmontrealauthorOct 18.2005 — Yes, the code for the element should look like that.

Like I said, you should concatenate them. Make sure to use a character or a few characters that won't appear in the array items.[/QUOTE]


Sorry, Kravvitz. I don't unstandard what do you mean by " Make sure to use a character or a few characters that won't appear in the array items.". ?
Copy linkTweet thisAlerts:
@Tweak4Oct 19.2005 — He means turn your array into a delimited list. Typically, I use either "~" or "|" whenever I need to do something like this.

If you have a JS array, "testArray" as follows:

testArray[0] = "element0";

testArray[1] = "element1";

testArray[2] = "element2";

the method testArray.join("|") would return the following string:

"element0|element1|element2"

Once you have this string where ever you need to manipulate the data within, you can use a string.split("|") to turn it back to the original array.

However, as stated above, make sure your delimiter isn't something that

would appear in the various array elements, or else the split() won't work quite right. If element[0] above was "elem|ent0", after you do the split, your new array would be:

testArray[0] = "elem";

testArray[1] = "ent0";

testArray[2] = "element1";

testArray[3] = "element2";

instead of the original array, so it's best to use a short cluster of unusual characters as your delimiter to limit the chances of something like this happening.
Copy linkTweet thisAlerts:
@KravvitzOct 19.2005 — Thank you for explaining what I meant, Tweak4. ?

reinmontreal, do you understand now?
×

Success!

Help @reinmontreal spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.23,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...