By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,817 Members | 2,152 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,817 IT Pros & Developers. It's quick & easy.

hidden and more values

P: n/a
if inner a form I have :
foreach ($arrayquery as $a)
{ echo <input type="hidden" name="x1" value=" $a->type" >;
echo <input type="hidden" name="x2" value=" $a->color" >;
echo <input type="hidden" name="x3" value=" $a->pos" >;
}

and in:
<script type=text/javascript>
var test1=document.form.x1;
var test2=document.form.x2;
var test3=document.form.x3;
....code
</script>

now I want to use only a field hidden for all value;
I thinked some similar:
$arr=[[$a->type]=>[$a->color,$a->pos]];
<input type="hidden" name="x1[]" value="$arr" >;
the problem is here (to put array) and after
in the script javascript
is there some example online or your solution ?
Aug 30 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
artev said the following on 8/30/2006 2:06 AM:
if inner a form I have :
foreach ($arrayquery as $a)
{ echo <input type="hidden" name="x1" value=" $a->type" >;
echo <input type="hidden" name="x2" value=" $a->color" >;
echo <input type="hidden" name="x3" value=" $a->pos" >;
}
If you view the source of that output, you will find that you have
multiple inputs with the same name attribute. You can't do that and
expect any reasonable response from scripting or even on the server.
and in:
<script type=text/javascript>
var test1=document.form.x1;
var test2=document.form.x2;
var test3=document.form.x3;
....code
</script>

now I want to use only a field hidden for all value;
I thinked some similar:
$arr=[[$a->type]=>[$a->color,$a->pos]];
<input type="hidden" name="x1[]" value="$arr" >;
If your PHP code is concatenating the array contents then the value of
the field will be all the values of all the inputs, is that what you wanted?
the problem is here (to put array) and after
in the script javascript
Huh? Just read it's value:

theValue = document.formID.elements['x1[]'].value;

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 30 '06 #2

P: n/a
Il Wed, 30 Aug 2006 02:50:08 -0400, Randy Webb ha scritto:
theValue = document.formID.elements['x1[]'].value;
this work I see 10000
code php
$fruits=10000;
echo <input type="hidden" name="x1[]" id="x1[]" value="$fruits" >;

code javascript
var test3 = document.formID.elements['x1[]'];
alert(test3[0].value);
---------------------------------------------------

that bottom, not work; I see in the alert the word: array
I want to use the array of array in the javascript's code
using the hidden's variable

code php
foreach ($arrayquery as $a)
{
$fruits = array($a['type'] =array(1 ='color', 2 ='pos'));
echo <input type="hidden" name="x1[]" id="x1[]" value="$fruits" >;
}

code javascript
var test3 = document.formID.elements['x1[]'];
alert(test3[0].value);
Aug 30 '06 #3

P: n/a
artev said the following on 8/30/2006 6:01 AM:
Il Wed, 30 Aug 2006 02:50:08 -0400, Randy Webb ha scritto:
>theValue = document.formID.elements['x1[]'].value;

this work I see 10000
code php
$fruits=10000;
echo <input type="hidden" name="x1[]" id="x1[]" value="$fruits" >;

code javascript
var test3 = document.formID.elements['x1[]'];
alert(test3[0].value);
---------------------------------------------------

that bottom, not work;
Thats because test3 is not an array. Also, is the ID of your form
element "formID" ?

Either way, you *should* be getting an error on the alert line.
I see in the alert the word: array
I want to use the array of array in the javascript's code
using the hidden's variable
If you want JS code, why not just produce JS code instead of trying to
put it into a hidden input and then reading it via JS? What you want to
ultimately do with that JS code will dictate how you want it created.
--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Aug 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.