User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 374,611 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,498 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2904 | Replies: 1
Reply
Join Date: Feb 2006
Posts: 1
Reputation: Kurupt4 is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Kurupt4 Kurupt4 is offline Offline
Newbie Poster

Form Fields

  #1  
Feb 24th, 2006
Hello Everyone,

I have a form (it is for a web based poll) it collects 4 pieces of information:

1) the poll question
2) the amoutn of choices
3) the start date of poll
4) the end date for poll

Now when this form is submitted(same script $php_self) it takes the amount of choices entered and
I run a for loop to get the amount of text-boxes I need in the new form, they are dynamically created using names choice1, choice2
and so on depending on the amount entered in the form before.

That is not the problem, that part is working great.

The problem comes in when I want to run a javascript script to get the values of the text fields, I use the following code:
elseif (isset($_POST['submit1'])) 
{ 
    $question = $_POST['question']; 
    $totalchoices= $_POST['totalchoices']; 
    $startdate = $_POST['startdate']; 
    $enddate = $_POST['enddate']; 
     
    $php_self = $_SERVER['PHP_SELF']; 
     
$steptwodata = <<<endofsteptwodata 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Web Poll Generator</title> 
<script language="javascript" type="text/javascript"> 
function checkForm(form)  
{    
    var howMany = form.elements.length; 
    var i = 0; 
     
                for (count = 0; count < howMany; count++) 
               { 
                    document.write(form.elements[count].value +"<br />"); 
               }     
    return false; 
} 
</script> 
</head> 
<body> 
<form name="formgenerator2" action="$php_self" method="post" onSubmit="return checkForm(this);"> 
<div align="center"> 
    <table border="1" cellpadding="5" cellspacing="0" width="600" bordercolor="#CCCCCC" bgcolor="#FFFF00"> 
        <tr> 
            <td> 
            <div align="center"> 
                <table border="1" cellpadding="5" cellspacing="0" width="100%" bordercolor="#DDDDDD" bgcolor="#FFFFFF" id="table2" style="font-family: Tahoma; font-size: 12px; color: #000000"> 
                    <tr> 
                        <td colspan="2"><p align="center"><font color="#008000"><b>Web Poll Generator</b></font></td> 
                    </tr> 
endofsteptwodata; 
for ($datacount = 0,$choicecount = 1; $datacount < $totalchoices; $datacount++,$choicecount++) 
{ 
$steptwodata .= <<<endofsteptwodata 

                    <tr> 
                        <td width="126" align="left">Choice $choicecount:</td> 
                        <td align="left"><input type="text" name="choice$choicecount" size="30" tabindex="$choicecount" style="font-family: Tahoma; font-size: 12px; color: #800000"></td> 
                         
                    </tr> 
endofsteptwodata; 
} 
$steptwodata .= <<<endofsteptwodata 
                    <tr> 
                        <input type="hidden" name="question" value="$question" /> 
                        <input type="hidden" name="totalchoices" value="$totalchoices" /> 
                        <input type="hidden" name="startdate" value="$startdate" /> 
                        <input type="hidden" name="enddate" value="$enddate" /> 
                        <td colspan="2" align="center"><input type="submit" value="Generate Poll" name="submit2" tabindex="99" style="font-family: Tahoma; font-size: 12px; color: #008000"></td> 
                    </tr> 
                    <tr> 
                </table> 
            </div> 
            </td> 
        </tr> 
    </table> 
</div> 
</form> 
endofsteptwodata; 
print $steptwodata;   

The problem is that for some reason it ONLY recognizes the very first text input and not the others.
All I get on the output is the value of the first text box not the others.

is there something I am doing wrong?

Is there anything in PHP that I could do to accomplish the same thing?

Any and all help will be greatly appreciated.

Thank you in advance

Leo Zayas
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation: Troy is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

Re: Form Fields

  #2  
Mar 5th, 2006
I'm not sure I understand your goal, but it appears that when a user submits the form, you don't want the form to submit anywhere--instead you want to display the values from the form at the bottom of the page--one per line?
From your code: [PHP]document.write(form.elements[count].value +"<br />");[/PHP]
If that's the case, I'd use a DIV. In your page, where you want the values to appear, add this line:
[PHP]<div id="values"></div>[/PHP]
Then, in your checkForm() function, replace your document.write line with something like:
[PHP]
document.getElementById('values').innerHTML += form.elements[count].value+"<br />";
[/PHP]

I'm not sure if I understood the issue--does this help you?
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 8:25 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC