PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > dynamic boxes problem... JS and PHP
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
dynamic boxes problem... JS and PHP

Réponse
 
LinkBack Outils de la discussion
Vieux 08/04/2008, 12h17   #1
Ryan S
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut dynamic boxes problem... JS and PHP

Hey everyone,

A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or .... just me.

(My money is on the last one :p )


Here's what I am trying to do:
In a form I have a listbox with the values 1-5, and under the listbox i have a <TD> with the id of "recips" (like so: <TD id='recips">

I have a onChange event linked to the list box and depending on what number the client picks it should dynamically put the number of text boxes there, here is the JS code:

///// ############### Start JS code ############
function change_no_of_recipients()
{
var nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;

if(nr>5){nr=5;} // max number of recipients
var msg = "";

for (var x = 1; x <= nr; x++)
{
msg += '<table width="50%" border="0" cellspacing="2" cellpadding="2">' +
'<tr>' +
'<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
'<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +
'<td nowrap="nowrap">Recipient\'s email:</td>' +
'<td><input type="text" name="rec_email[]" id="rec_email[]" /></td>' +
'</tr>' +
'<tr>' +
'</table>';
}

document.getElementById('recips').innerHTML=msg;
}

///// ##################### End JS code ################

So far on the page everything is working, but when I click the submit button this is my PHP processing script:

<?php
print_r($_REQUEST);
?>


It shows me everything that has been submitted but NOT any of the above dynamically made boxes values... but get this, it DOES show me all values... in IE7 _not_ in FF (am using 2.0.0.13)

Anybody else face anything like this?
Is this a bug in FF? Is $_REQUEST wrong to catch this?
Dont know what the @#$@ to do... ANY even a link to a site which can shed a little light would be appreciated.

Thanks in advance.

/Ryan



__________________________________________________ __________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
  Réponse avec citation
Vieux 08/04/2008, 15h30   #2
Mark Weaver
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

Ryan S wrote:
> Hey everyone,
>
> A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or .... just me.
>
> (My money is on the last one :p )
>
>
> Here's what I am trying to do:
> In a form I have a listbox with the values 1-5, and under the listbox i have a <TD> with the id of "recips" (like so: <TD id='recips">
>
> I have a onChange event linked to the list box and depending on what number the client picks it should dynamically put the number of text boxes there, here is the JS code:
>
> ///// ############### Start JS code ############
> function change_no_of_recipients()
> {
> var nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;
>
> if(nr>5){nr=5;} // max number of recipients
> var msg = "";
>
> for (var x = 1; x <= nr; x++)
> {
> msg += '<table width="50%" border="0" cellspacing="2" cellpadding="2">' +
> '<tr>' +
> '<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
> '<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +
> '<td nowrap="nowrap">Recipient\'s email:</td>' +
> '<td><input type="text" name="rec_email[]" id="rec_email[]" /></td>' +
> '</tr>' +
> '<tr>' +
> '</table>';
> }
>
> document.getElementById('recips').innerHTML=msg;
> }
>
> ///// ##################### End JS code ################
>
> So far on the page everything is working, but when I click the submit button this is my PHP processing script:
>
> <?php
> print_r($_REQUEST);
> ?>
>
>
> It shows me everything that has been submitted but NOT any of the above dynamically made boxes values... but get this, it DOES show me all values... in IE7 _not_ in FF (am using 2.0.0.13)
>
> Anybody else face anything like this?
> Is this a bug in FF? Is $_REQUEST wrong to catch this?
> Dont know what the @#$@ to do... ANY even a link to a site which can shed a little light would be appreciated.
>
> Thanks in advance.
>
> /Ryan
>


Hi Ryan,

Since I'm relatively new to PHP I could be off on this, but I'd say yes,
$_REQUEST is wrong. I would think you'd want to use $_POST to receive
the incoming values from a form.

--

Mark
-------------------------
the rule of law is good, however the rule of tyrants just plain sucks!
Real Tax Reform begins with getting rid of the IRS.
==============================================
Powered by CentOS5 (RHEL5)
  Réponse avec citation
Vieux 08/04/2008, 16h00   #3
Andrew Ballard
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

On Tue, Apr 8, 2008 at 9:30 AM, Mark Weaver <mdw1982@mdw1982.com> wrote:
> Ryan S wrote:
>
> > Hey everyone,
> >
> > A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or

> .... just me.
> >
> > (My money is on the last one :p )
> >
> >
> > Here's what I am trying to do:
> > In a form I have a listbox with the values 1-5, and under the listbox i

> have a <TD> with the id of "recips" (like so: <TD id='recips">
> >
> > I have a onChange event linked to the list box and depending on what

> number the client picks it should dynamically put the number of text boxes
> there, here is the JS code:
> >
> > ///// ############### Start JS code ############
> > function change_no_of_recipients()
> > {
> > var

> nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;
> > if(nr>5){nr=5;} // max number of recipients
> > var msg = "";
> >
> > for (var x = 1; x <= nr; x++)
> > {
> > msg += '<table width="50%" border="0" cellspacing="2" cellpadding="2">'

> +
> > '<tr>' +
> > '<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
> > '<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +
> > '<td nowrap="nowrap">Recipient\'s email:</td>' +
> > '<td><input type="text" name="rec_email[]" id="rec_email[]" /></td>' +
> > '</tr>' +
> > '<tr>' +
> > '</table>';
> > }
> > document.getElementById('recips').innerHTML=msg;
> > }
> >
> > ///// ##################### End JS code ################
> >
> > So far on the page everything is working, but when I click the submit

> button this is my PHP processing script:
> >
> > <?php
> > print_r($_REQUEST);
> > ?>
> >
> >
> > It shows me everything that has been submitted but NOT any of the above

> dynamically made boxes values... but get this, it DOES show me all values...
> in IE7 _not_ in FF (am using 2.0.0.13)
> >
> > Anybody else face anything like this?
> > Is this a bug in FF? Is $_REQUEST wrong to catch this? Dont know what the

> @#$@ to do... ANY even a link to a site which can shed a little light
> would be appreciated.
> >
> > Thanks in advance.
> >
> > /Ryan
> >
> >

>
> Hi Ryan,
>
> Since I'm relatively new to PHP I could be off on this, but I'd say yes,
> $_REQUEST is wrong. I would think you'd want to use $_POST to receive the
> incoming values from a form.
>
> --
>
> Mark


I think in this case $_REQUEST and $_POST should both get you what you
want. I'm wondering whether your javascript is inserting the form
fields within the correct <FORM></FORM> tags.

Also, FWIW, I doubt it has anything to do with your problem but you
are assigning the same value for ID each time through the loop. The ID
attribute is supposed to be unique for each element on the page.

Andrew
  Réponse avec citation
Vieux 08/04/2008, 16h06   #4
Peter Ford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

Mark Weaver wrote:
> Ryan S wrote:
>> Hey everyone,
>>
>> A bit of a puzzle here, dont know if this is a JS problem or PHP or FF
>> or .... just me.
>>
>> (My money is on the last one :p )
>>
>>
>> Here's what I am trying to do:
>> In a form I have a listbox with the values 1-5, and under the listbox
>> i have a <TD> with the id of "recips" (like so: <TD id='recips">
>>
>> I have a onChange event linked to the list box and depending on what
>> number the client picks it should dynamically put the number of text
>> boxes there, here is the JS code:
>>
>> ///// ############### Start JS code ############
>> function change_no_of_recipients()
>> {
>> var
>> nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;
>>
>> if(nr>5){nr=5;} // max number of recipients
>> var msg = "";
>>
>> for (var x = 1; x <= nr; x++)
>> {
>> msg += '<table width="50%" border="0" cellspacing="2"
>> cellpadding="2">' +
>> '<tr>' +
>> '<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
>> '<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +
>> '<td nowrap="nowrap">Recipient\'s email:</td>' +
>> '<td><input type="text" name="rec_email[]" id="rec_email[]"
>> /></td>' +
>> '</tr>' +
>> '<tr>' +
>> '</table>';
>> }
>> document.getElementById('recips').innerHTML=msg;
>> }
>>
>> ///// ##################### End JS code ################
>>
>> So far on the page everything is working, but when I click the submit
>> button this is my PHP processing script:
>>
>> <?php
>> print_r($_REQUEST);
>> ?>
>>
>>
>> It shows me everything that has been submitted but NOT any of the
>> above dynamically made boxes values... but get this, it DOES show me
>> all values... in IE7 _not_ in FF (am using 2.0.0.13)
>>
>> Anybody else face anything like this?
>> Is this a bug in FF? Is $_REQUEST wrong to catch this? Dont know what
>> the @#$@ to do... ANY even a link to a site which can shed a
>> little light would be appreciated.
>>
>> Thanks in advance.
>>
>> /Ryan
>>

>
> Hi Ryan,
>
> Since I'm relatively new to PHP I could be off on this, but I'd say yes,
> $_REQUEST is wrong. I would think you'd want to use $_POST to receive
> the incoming values from a form.
>


That would depend on the method that the form is using: GET or POST.

I don't think that's the answer.

Two things I would suggest:

1. Check that the Javascript is doing what you expect: you *are* using Firebug
on Firefox, aren't you? Also the WebDeveloper toolbar plugin is useful - it has
a View Generated Source tool which will show you what Firefox thinks your page
actually looks like after the JS has run...

2. Check that the TD you are loading with content is actually inside the <FORM>
tags - otherwise the inputs won't be included in the request/post variables...

Cheers
Pete

--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent
  Réponse avec citation
Vieux 08/04/2008, 16h42   #5
Daniel Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

On Tue, Apr 8, 2008 at 6:17 AM, Ryan S <genphp@yahoo.com> wrote:
> Hey everyone,
>
> A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or .... just me.
>
> (My money is on the last one :p )

[snip!]

Ryan, would it be possible for you to send an actual link to the
page in question? You'll probably wind up with some better feedback
with a real-world test in this particular case.

--
</Daniel P. Brown>
Ask me about:
Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo.,
and shared hosting starting @ $2.50/mo.
Unmanaged, managed, and fully-managed!
  Réponse avec citation
Vieux 08/04/2008, 18h49   #6
Jim Lucas
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

Ryan S wrote:
> Hey everyone,
>
> A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or .... just me.
>
> (My money is on the last one :p )
>
>
> Here's what I am trying to do:
> In a form I have a listbox with the values 1-5, and under the listbox i have a <TD> with the id of "recips" (like so: <TD id='recips">
>
> I have a onChange event linked to the list box and depending on what number the client picks it should dynamically put the number of text boxes there, here is the JS code:
>
> ///// ############### Start JS code ############
> function change_no_of_recipients()
> {
> var nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;
>
> if(nr>5){nr=5;} // max number of recipients
> var msg = '<table width="50%" border="0" cellspacing="2" cellpadding="2">';


Move your table opening outside the loop

>
> for (var x = 1; x <= nr; x++)
> {
> msg += '<tr>' +
> '<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
> '<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +


first off, in the world of CSS, this id would not be unique or valid for that
matter. id attributes can only contain numbers, letters, and underscores.

Don't think that is related to your problem, but it was something I thought I
would point out.

> '<td nowrap="nowrap">Recipient\'s email:</td>' +
> '<td><input type="text" name="rec_email[]" id="rec_email[]" /></td>' +
> '</tr>' +
> '<tr>';
> }

msg += '</table>';
move your table closing outside the loop.

> document.getElementById('recips').innerHTML=msg;
> }
>
> ///// ##################### End JS code ################
>
> So far on the page everything is working, but when I click the submit button this is my PHP processing script:
>
> <?php
> print_r($_REQUEST);
> ?>
>
>
> It shows me everything that has been submitted but NOT any of the above dynamically made boxes values... but get this, it DOES show me all values... in IE7 _not_ in FF (am using 2.0.0.13)
>
> Anybody else face anything like this?
> Is this a bug in FF? Is $_REQUEST wrong to catch this?
> Dont know what the @#$@ to do... ANY even a link to a site which can shed a little light would be appreciated.


Do you have your <form ..>...</form> defined?

Show us the actual output of the print_r() call above.

>
> Thanks in advance.
>
> /Ryan
>
>
>
> __________________________________________________ __________________________________
> You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
> http://tc.deals.yahoo.com/tc/blockbuster/text5.com
>



--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare

  Réponse avec citation
Vieux 09/04/2008, 09h58   #7
Peter Ford
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] dynamic boxes problem... JS and PHP

Peter Ford wrote:
> Mark Weaver wrote:
>> Ryan S wrote:
>>> Hey everyone,
>>>
>>> A bit of a puzzle here, dont know if this is a JS problem or PHP or
>>> FF or .... just me.
>>>
>>> (My money is on the last one :p )
>>>
>>>
>>> Here's what I am trying to do:
>>> In a form I have a listbox with the values 1-5, and under the
>>> listbox i have a <TD> with the id of "recips" (like so: <TD id='recips">
>>>
>>> I have a onChange event linked to the list box and depending on what
>>> number the client picks it should dynamically put the number of text
>>> boxes there, here is the JS code:
>>>
>>> ///// ############### Start JS code ############
>>> function change_no_of_recipients()
>>> {
>>> var
>>> nr=document.mainform.no_of_friends.options[document.mainform.no_of_friends.selectedIndex].value;
>>>
>>> if(nr>5){nr=5;} // max number of recipients
>>> var msg = "";
>>>
>>> for (var x = 1; x <= nr; x++)
>>> {
>>> msg += '<table width="50%" border="0" cellspacing="2"
>>> cellpadding="2">' +
>>> '<tr>' +
>>> '<td nowrap="nowrap">'+ x +'. Recipient\'s name:</td>' +
>>> '<td><input type="text" name="rec_name[]" id="rec_name[]" /></td>' +
>>> '<td nowrap="nowrap">Recipient\'s email:</td>' +
>>> '<td><input type="text" name="rec_email[]" id="rec_email[]"
>>> /></td>' +
>>> '</tr>' +
>>> '<tr>' +
>>> '</table>';
>>> }
>>> document.getElementById('recips').innerHTML=msg;
>>> }
>>>
>>> ///// ##################### End JS code ################
>>>
>>> So far on the page everything is working, but when I click the submit
>>> button this is my PHP processing script:
>>>
>>> <?php
>>> print_r($_REQUEST);
>>> ?>
>>>
>>>
>>> It shows me everything that has been submitted but NOT any of the
>>> above dynamically made boxes values... but get this, it DOES show me
>>> all values... in IE7 _not_ in FF (am using 2.0.0.13)
>>>
>>> Anybody else face anything like this?
>>> Is this a bug in FF? Is $_REQUEST wrong to catch this? Dont know what
>>> the @#$@ to do... ANY even a link to a site which can shed a
>>> little light would be appreciated.
>>>
>>> Thanks in advance.
>>>
>>> /Ryan
>>>

>>
>> Hi Ryan,
>>
>> Since I'm relatively new to PHP I could be off on this, but I'd say
>> yes, $_REQUEST is wrong. I would think you'd want to use $_POST to
>> receive the incoming values from a form.
>>

>
> That would depend on the method that the form is using: GET or POST.
>
> I don't think that's the answer.
>
> Two things I would suggest:
>
> 1. Check that the Javascript is doing what you expect: you *are* using
> Firebug on Firefox, aren't you? Also the WebDeveloper toolbar plugin is
> useful - it has a View Generated Source tool which will show you what
> Firefox thinks your page actually looks like after the JS has run...
>
> 2. Check that the TD you are loading with content is actually inside the
> <FORM> tags - otherwise the inputs won't be included in the request/post
> variables...
>
> Cheers
> Pete
>


Ryan,

First, you should reply to the list - that way more people could see the links
you posted and out.

Right,

It looks like there may be a problem with the form tags - when I look at this
code I see
<form action="process_ecard1.php" method="post" name="mainform"></form>

That looks like you've closed your "mainform" before defining the inputs

Don't know why IE works, but it's probably trying to be ful...



--
Peter Ford phone: 01580 893333
Developer fax: 01580 893399
Justcroft International Ltd., Staplehurst, Kent
  Réponse avec citation
Vieux 10/04/2008, 10h47   #8
David Lidstone
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: dynamic boxes problem... JS and PHP

Ryan S wrote:
> Hey everyone,
>
> A bit of a puzzle here, dont know if this is a JS problem or PHP or FF or .... just me.
>
> (My money is on the last one :p )
>
>
> Here's what I am trying to do:
> In a form I have a listbox with the values 1-5, and under the listbox i have a <TD> with the id of "recips" (like so: <TD id='recips">
>

<snip>

Hi

Probably just a typo in your original message, but your TD above has an
id which opens with ' and closes with ". I know I have done this before!
. It does also sound like a possible 'wellformedness' issue as you
have different results from IE and Fx.

Good luck, David
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 02h40.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,25343 seconds with 16 queries