• 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.

[Javascript/PHP] Horrible problem with dynamically loading content

FromHollandWithLove

Junior Member
Hi. I've been working for hours on this script and it's really starting to get on my nerves now.

First i'll show you what i am talking about: > www.odessa.nl/enquete/hoeveel.html is a wizard that generates a quastionaire. On the second page 'make_page.php' the user can fill out questions and select a response type for each question.
I want a different form to be loaded when each of the response type radio buttons is clicked, buy HOW???

I have seen a lot of examples on the internet using div, innerhtml and other Javscript functions, but i didn't get it to work. 🙁
A problem is that make_page.php is dynamically created by PHP, so any 'id' will have to be based on the variable $i from the for loop. Could someone help me out, or even code something for me? I know this isn't too hard, but i can't seem to figure out the right way to do it.

Thanks very much in advance!


<html>
<head>
<title>Questions</title>

<script language="Javascript">

function cell_create(row, r_type)
{

/* This function should decide what form to load in cell$i */


}
</script>

</head>
<body>
<?php

echo "<table bgcolor='#000000' cellpadding='4' cellspacing='1'><tr><td colspan='4' bgcolor='#f5f5f5'>Your questionaire will contain <b>$aantal</b> questions. Fill out the questions below and select a response type for every question </td></tr>";

echo "<tr bgcolor='#f5f5f5'><td><b>nr</b></td><td><b>question/statement</b></td><td><b>response type</b></td><td width=150><b>specify</b></td></tr>";

for($i=1; $i <=$aantal; $i++)
{
echo "<tr valign=\"top\" bgcolor='#f5f5f5'><td><b>$i</b></td>";
echo "<td><textarea name='vraag$i' rows='4' cols='32'>Fill out question</textarea></td>";
echo "<td>
<input type='radio' name='type_vraag$i' value='type_open' onClick=\"cell_create($i, 1)\">open
<input type='radio' name='type_vraag$i' value='type_number' onClick=\"cell_create($i, 2)\">list of numbers
<input type='radio' name='type_vraag$i' value='type_word' onClick=\"cell_create($i, 3)\">list of words
</td>

<td nowrap id=cell$i>

/* This is where the form should be loaded, depending on what radio box was selected */

</form>


</td></tr>";
}
echo "</table>";

?>

</body>
</html>
 
You could try changing the form's Action property in JavaScript in the OnClick event for the radio button(s). Write a function that is called when a radio button is clicked that changes the action property of the form to page you want to display. Then call document.forms[0].submit automatically to redirect to that form.

Alternatively, you could simply do a document.location.href to the form you wish to load in the OnClick event.
 
Back
Top