471,336 Members | 997 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,336 software developers and data experts.

How to get a Dynamic Javacript Form variables seperated in PHP

Appreciate any help!!!

PROBLEM: I have this form that allows the user to dynamically create
additional fields (see javascript code bellow). I am trying to retrieve
the values entered into these fields from my php script. I ultimatly
need to pick out the variables and place the values into my php script
page. I have worked with a little code I found on php.net (see php code
below), but I wan unable to grasp the knowledge on how to seperate the
variables in the address bar. Please reply.

QUESTION: How do I create variables in my php script from my dynamic
javascript form?

PHP CODE:
foreach($_GET as $name => $value) {
print "$name : $value<br>";
}

JAVASCRIPT CODE:
<HEAD>
<!-- Begin
function createForm(number) {
data = "";
inter = "'";
if (number < 16 && number > -1) {
for (i=1; i <= number; i++) {
if (i < 10) spaces=" ";
else spaces=" ";
data = data + "URL " + i + " :" + spaces
+ "<input type='text' size=10 name=" + inter
+ "url" + i + inter + "'><br>";
}
if (document.layers) {
document.layers.cust.document.write(data);
document.layers.cust.document.close();
}
else {
if (document.all) {
cust.innerHTML = data;
}
}
}
else {
window.alert("Please select up to 15 entries.");
}
}
// End -->
</script>
</HEAD>
<BODY>
<center>
<form name=counter>
Number of URLs to enter:
<input type=text name=number size=5>
<input type=button value="Update"
onClick="createForm(counter.number.value);">
</form>
<br>
<form name="webform" action="get.php">
<input type=text size=20 name=name onChange="msg(this.form)">
<!-- Placeholder for dynamic form contents -->
<span id=cust style="position:relative;"></span>
<input type=submit value="Send">
</form>

Jul 17 '05 #1
11 2233
I noticed that Message-ID:
<11********************@z14g2000cwz.googlegroups.c om> from propizzy
contained the following:

well I'd do it all with PHP but...

data = data + "URL " + i + " :" + spaces
+ "<input type='text' size=10 name=" + inter
+ "url[]" + i + inter + "'><br>";

adding square brackets to the name of the text box means the urls will
be added to an array.

<form name="webform" action="get.php">

you need to change this to

<form name="webform" method="post" action="get.php">

Then you can do this

$urls=$_POST['url'];

foreach($urls as $key=>$value){
$key++;
echo "URL#$key: $value<br>\n";
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2
Thanks for the reply Geoff,

I'm going to change my Javascript to PHP first, then I'll try it. I put
the brackets in the url and paste the code you supplied in my get.php
page and I got the following errors. I also changed the method to post.
Please check back later...

Notice: Undefined index: url in D:\My Webs\My Extreme Web\get.php on
line 11
Warning: Invalid argument supplied for foreach() in D:\My Webs\My
Extreme Web\get.php on line 14

~propizzy

Jul 17 '05 #3
Thanks for the reply Geoff,

I'm going to change my Javascript to PHP first, then I'll try it. I put
the brackets in the url and paste the code you supplied in my get.php
page and I got the following errors. I also changed the method to post.
Please check back later...

Notice: Undefined index: url in D:\My Webs\My Extreme Web\get.php on
line 11
Warning: Invalid argument supplied for foreach() in D:\My Webs\My
Extreme Web\get.php on line 14

~propizzy

Jul 17 '05 #4
never mind I messed up because I changed your $urls=$_POST['url']; to
$urls=$_GET['url'];... Now that I changed it back it works. Thanks for
the help

Jul 17 '05 #5
I noticed that Message-ID:
<11**********************@c13g2000cwb.googlegroups .com> from propizzy
contained the following:
never mind I messed up because I changed your $urls=$_POST['url']; to
$urls=$_GET['url'];... Now that I changed it back it works. Thanks for
the help


:-)
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6
Geoff,

Maybe you can help me with this.

PROBLEM: Trying to take a couple foreach statements and control the
output. My dynamic form now has an additional input text box that
submits to the PHP CODE below. I need to take the values out of the 1st
input ("system") plus 2nd input ("ipaddress") and eliminate the values
in the middle (please see RESULTS below).

QUESTION: How can I control the output of these foreach statements to
ultimately eliminate the two middle results?

NOTE: Middle values are noted with an star *.

PHP CODE:
//create vlan <system> and <ipaddress>
foreach($system as $key=>$value1){
$key++;
foreach($ipaddress as $key2=>$value2){
$key2++;
echo "create system $value1 <br>\n";
echo "configure $value1 ipaddress $value2 <br>\n";
}
}

RESULTS:
create system system1
configure system1 ipaddress 10.10.10.2
*create system system1
*configure system1 ipaddress 10.10.10.3
*create system system2
*configure system2 ipaddress 10.10.10.2
create system system2
configure system2 ipaddress 10.10.10.3

Jul 17 '05 #7
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from propizzy
contained the following:
PHP CODE:
//create vlan <system> and <ipaddress>
foreach($system as $key=>$value1){
$key++;
foreach($ipaddress as $key2=>$value2){
$key2++;
echo "create system $value1 <br>\n";
echo "configure $value1 ipaddress $value2 <br>\n";
}
}


Well if I have this right you have an array of systems and a
corresponding array of ip addresses, each with the same number of
elements and each with sequential array keys?

If so...

for($i=0;$i<count($system);$i++){
echo "create system ".$system[$i]." <br>\n";
echo "configure ".$system[$i]." ipaddress ."$ipaddress[$i]." <br>\n";
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #8
that is tight!!!! (as they say here in California)... Thanks Dude!

Jul 17 '05 #9
I noticed that Message-ID:
<11**********************@o13g2000cwo.googlegroups .com> from propizzy
contained the following:
that is tight!!!! (as they say here in California)... Thanks Dude!


I hope it's a compliment, in the UK 'tight' either means drunk or
miserly. :-)

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10
JDS
On Wed, 23 Feb 2005 19:20:36 +0000, Geoff Berrow wrote:
I hope it's a compliment, in the UK 'tight' either means drunk or
miserly. :-)


http://www.ocf.berkeley.edu/~wrader/slang/t.html

--
JDS | je*****@example.invalid
| http://www.newtnotes.com
DJMBS | http://newtnotes.com/doctor-jeff-master-brainsurgeon/

Jul 17 '05 #11
nice hook up jeff...

Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Nathan Bloomfield | last post: by
1 post views Thread by Will | last post: by
2 posts views Thread by deejayquai | last post: by
26 posts views Thread by Jerim79 | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.