I get a notice error when I open up my page
<p>Hopefully this question makes sense. I want to display a message using javascript if a room number entered in a textbox is in the database or not. If it is in the database then display nothing (""), if it isn't in the database then display a message "Room is Invalid".</p>

<p>The problem is though when I open up the page where the textbox is stored, it comes up with a notice saying:</p>

<blockquote>
  <p>Notice: Undefined index: roomChosen in /web/stud/Mobile_app/create_session.php on line 287</p>
</blockquote>

<p>Now I believe the reason it is stating this error is because nothing is being posted before this page is opened. This is suppose to post the room number entered in the textbox but obviously the textbox for the room number is on the same page so it can't post it before the page is open. What I want is the user to do this:</p>

<p>step 1: Enter in a room number in the textbox</p>

<p>step 2: Click on the submit button</p>

<p>step 3: Check to see if room number in textbox is in database</p>

<p>step 4: display message depending if room number is in database or not</p>

<p>So what I want to know is how can I store the php coding so that it checks to see if the room number in textbox is in database or not after the submit button is clicked?</p>

<p>Below is html of the room number textbox and submit button:</p>

<pre><code>//textbox where room number is entered in

&lt;p&gt;&lt;strong&gt;10: Room:&lt;/strong&gt; &lt;input type="text" id="room" name="roomChosen" roomthere="&lt;?php echo $room_there; ?&gt;" /&gt;

//message displayed if room number is in database or not

&lt;br/&gt;&lt;span id="roomAlert"&gt;&lt;/span&gt;&lt;/p&gt;  


// submit button 

&lt;p&gt;&lt;input class="questionBtn" type="button" value="Prepare Questions" name="prequestion" onClick="myClickHandler()"/&gt;&lt;/p&gt;
</code></pre>

<p>Below is php which checks to if room number in textbox is in database or not:</p>

<pre><code>$room_there = true;

$roomresult = mysql_query( "SELECT Room FROM Room WHERE Room = " . (int) $_POST['roomChosen']);

if( mysql_num_rows( $roomresult ) == 0 ) $room_there = false;
</code></pre>

<p>Below is the handler which handles the submit button when it is clicked:</p>

<pre><code>function myClickHandler(){
    if(validation()){
        showConfirm();
    }
}
</code></pre>

<p>Javascript validation for room number textbox:</p>

<pre><code>var roomTextO = document.getElementById("room"); 

var errRoomMsgO = document.getElementById("roomAlert");

          if (roomTextO.value == ""){
          errRoomMsgO.innerHTML = "Please Enter in a Room Number";
          isDataValid = false;

            }else if (!trimmedRoomText.length){
          errRoomMsgO.innerHTML = "Please Enter in a Room Number"; 
          isDataValid = false;  

      }else if(roomTextO.getAttribute("roomthere") == false){
          errRoomMsgO.innerHTML = "This Room is Invalid"; 

        }else{
                errRoomMsgO.innerHTML = ""; 
            }
</code></pre>
