0

I'm currently busy with a database project. The idea is that you can select an option and when some options are selected the HTML form changes. I've got that all going, the only problem I have got now is that the PHP file, to which the form redirects, doesn't recognize the textbox which is placed there by a JavaScript function.

JavaScript and HTML:

<head>
<script>
function myFunction(submittedValue) {
if(submittedValue == "URL"){
var x = "URL:";
var y = "<input type='text' name='URL'>";
} else {
var x = "Bestand:";
var y = "<input type='file' name='fileToUpload' id='fileToUpload'>";
}
document.getElementById("x").innerHTML = x;
document.getElementById("y").innerHTML = y;
} 
</script>
</head>
<html>
<body onload="myFunction('URL')">
<table>
<form action='Brontoevoegen_verwerking1.php' method='POST'  enctype='multipart/form-data'>
<tr><td><p id='x'></p></td><td><p id='y'>N/p></td></tr>
</table>

PHP:

<?php
$URL = $_POST["URL"];
echo "$URL";
?>

Whenever I execute the PHP file I get the following error:

Notice: Undefined index: URL in /home/******/http/Brontoevoegen_verwerking1.php on line 15

0

1 Answer 1

3

The input doesn't even end up in the form at all, you end up with

<table>
    <form action="Brontoevoegen_verwerking1.php" method="POST" enctype="multipart/form-data">
    </form>

    <!-- form closed :O -->

    <tbody>
        <tr>
           <td>
               <p id="x">URL:</p>
           </td>
           <td>
               <p id="y">
                  <input type="text" name="URL">
               </p>
           </td>
        </tr>
    </tbody>
</table>

because your HTML is invalid, you can't have a form element as a direct child in a table, or rows and cells directly in a form etc.

Sign up to request clarification or add additional context in comments.

2 Comments

alright, never mind. When I set the <form> line above the <table> line, everything just worked fine.
Yes, you can have a table inside a form, and you can even have a form inside a table, but a table can't have a form as a direct child, you need to know the basics of HTML.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.