• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

HTML form making problem

hey all,
I'm tring to pass a form value inthe example below...

<form name="basis" method="post">
<p>Project Name: <input type="text" name="project_name"></p>
<p>Number of Periods: <input type="text" value="0" name="number_of_periods"></p>
</form>

im trying to print the value of the 'number_of_period' on the page but i can't pass it. PLease guide me.
 
You need an action="whateverPage" in the form tag.

And HTML will not process post. You need a script (the whateverPage) to process that.
 
Yeah i know i made a action.php page that prints it out the values but in a separate page...
but I want to be able to pass around values from the form inside the page itself...

specifically I want the user to enter the number of PERIOD forms and the page will display that amount of forms in the same page...

Thanks for the reply though.
 
Just post the form to itself, if I'm understanding you correctly.

Or I think you might be needing a little javascript if that's not what you want.
 
Well ... i don't know what you mean by postin the form to itself, but i'll think about it... im using a bit javascript aswell.. this is what i have so far....

[img=[url="http://img399.imageshack.us/img399/3678/testinau4.gif"]http://img399.imageshack.us/img399/3678/testinau4.gif[/url]][/url]


and basically i want to type in lets say 10 in the period form and get 10 textboxes each one askin for a name lets say...

this is my code and basically i have to figure out a function to add forms indicated with the $$$$$$$$ sign..
CODE:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script>

var arrInput = new Array(0);
var arrinputValue = new Array(0);

function value_getter (form) {
var TestVar = form.number_of_periods.value;
return TestVar;
}

function create_period(int){

for(i=1 ; i <= int ; i++){

$$$$$$$$
<!-- this is the most complicate dsection ever mannnn -->
}
}


</script>
</head>

<body>
<form name="project" action="graph_builder.php" method="post">
<p>Project Name: <input type="text" name="project_name"></p>
<p>Number of Periods: <input type="text" value="" name="number_of_periods">
<input type="button" value="set" name="set" ******="create_period(value_getter(this.form))"> </p>
<p id="empty_space"> </p>
<p><input type="submit" /></p>
</form>


</body>
</html>
 
Well, it should be simple enough. First off, your form should reside on a php file, not html. So you have page called test.php with the form on it.

<form action="test.php">
<input.....
</form>

That will post to itself. Then to process the post, near the top of the script you have something like this:

<?php
$fields = '';
for($i=0; $i<$_POST['number_of_periods']; $i++) {
$fields .= '<p><input type="text" name="nameYouWant[]" /></p>';
}
?>

Then you can print $fields wherever you want and the number of fields requested will show up on the form.

You can even get rid of the initial form and subsitute a new form by doing something like this:

<?php if ($_POST['submit']) { ?>

<form action="finalProcess.php" method="post">
<?php echo $fields; ?>
<input type="submit" value="Submit" />
</form>

<?php } else { ?>

<form name="project" action="test.php" method="post">
<p>Project Name: <input type="text" name="project_name"></p>
<p>Number of Periods: <input type="text" value="" name="number_of_periods">
<input type="button" value="set" name="set" ******="create_period(value_getter(this.form))"> </p>
<p id="empty_space"> </p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
<?php } ?>

You'll note that you have to give the submit type input a name called submit.

Also, that will put the name fields into an array; notice the brackets [] included. So when you process the post, $_POST['nameYouWant'] will be an array of however many fields were requested. You could also do something like this if you didn't want them in an array:

$fields .= '<p><input type="text" name="name'.$i.'/></p>';

That will give you name followed by a corresponding number for that field: name0, name1, name2, etc.

Edit again: Ah, I just reread your post and yeah, you want to use javascript to display the number of fields. Sorry, can't help you there. 🙂
 
Still thank you very much... I would try that. And i understood this section but not much the coding...But i get the idea of what your impling.

""
<?php

if ($_POST['submit']) {

?> <--i didn't know you can end a php command here, in the middle of a if statement.

<form action="finalProcess.php" method="post">
<?php echo $fields; ?>
<input type="submit" value="Submit" />
</form>

<?php
}
else { ?>

<form name="project" action="test.php" method="post">
<p>Project Name: <input type="text" name="project_name"></p>
<p>Number of Periods: <input type="text" value="" name="number_of_periods">
<input type="button" value="set" name="set" ******="create_period(value_getter(this.form))"> </p>
<p id="empty_space"> </p>
<p><input type="submit" name="submit" value="Submit" /></p>
</form>
<?php } ?>

""


Actually I got it... I'll post whatever i have uncluding the java scripts i added from http://javascriptsource.com" ... i have to modify it better so when the user re enters the number of periods, it won't be added to the previous fields.

I was wondering If it's posiblle to have a frame inside the page so when the user clicks the submit button the information on the forms would still be available to the user. Like having the PHP file indside a frame on the page.
 
THE OUTPUT:

[img=[url="http://img124.imageshack.../img124.imageshack.us/img124/43/testinis2.gif][/url]



THE CODE:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<script>

var arrInput = new Array(0);
var arrInputValue = new Array(0);

function value_getter (form) {
var TestVar = form.number_of_periods.value;
return TestVar;
}

function addInput() {
//arrInput.push(createInput(arrInput.length));
arrInput.push(arrInput.length);
//arrInputValue.push(arrInputValue.length);
arrInputValue.push("");
display();
}

function display() {
document.getElementById('empty_space').innerHTML="";
for (intI=0;intI<arrInput.length;intI++) {
document.getElementById('empty_space').innerHTML+=createInput(arrInput[intI], arrInputValue[intI]);
}
}

function saveValue(intId,strValue) {
arrInputValue[intId]=strValue;
}

function createInput(id,value) {
return " Period "+ id +" : <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'> duration : <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'> Downlink: <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'> Dataintake : <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'> Number of Tracks : <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'> Track Duration: <input type='text' id='test "+ id +"' onChange='javascript:saveValue("+ id +",this.value)' value='"+ value +"'><br>";
}

function create_period(int){
for(i=1 ; i <= int ; i++){
addInput();
}
}

</script>
</head>

<body>
<form name="project" action="graph_builder.php" method="post">
<p>Project Name: <input type="text" name="project_name"></p>
<p>Number of Periods: <input type="text" value="" name="number_of_periods">
<input type="button" value="set" name="set" ******="create_period(value_getter(this.form))"> </p>
<p id="empty_space"> </p>
<p><input type="submit" /></p>
</form>


<p><center>
<font face="arial, helvetica" SIZE="-2">Free JavaScripts provided<br>
by <a href="http://javascriptsource.com">The JavaScript Source</a></font>
</center><p>

</body>
</html>
 
Back
Top