Use HTML Form Select On Click with PHP
I have been searching all day for a solution to my latest problem.
I am using PHP to dynaically create select form options. What I want to be
able to do is use the onclick function to pass a variable to PHP and then
use it later on. I have seen many posts referring to AJAX which is
something I am not familiar with at all.
My current thinking is to have the onclick post data to the server and set
a variable.
The other thing I should mention is that I am using JQuery to hide
elements of the page based on the selection.
This is my code:
<div class="span5">
<form method="post" action="index.php">
<fieldset>
<label>Instances</label>
<select name="inst">
<option value="pleaseSel"
onclick="$('#lsList').hide('fast');
$('#newSpecDetails').hide('fast');">Please
Select...</option>
<?php
$instSelect = $dbObj->select("*", "inst_reg");
foreach ($instSelect as $value){
echo "<option name=\"spec_name\" value=\"" .
$value['spec_name'] . "\"
onclick=\"$('#lsList').show('fast');
$('#newSpecDetails').hide('fast'); \">" .
$value['spec_name'] . "</option>";
};
?>
<option value="newSpec"
onclick="$('#newSpecDetails').show('fast');
$('#lsList').hide('fast');">New...</option>
</select>
<div class="csvUp hide">
<label>Please select a CSV file for upload</label>
<input name="csvFile" type="file" placeholder="Path to
file..." required><br><br>
<button class="btn btn-success" type="submit" value="go"
name="gobabygo" class="btn">Go Baby Go...</button><br>
</div>
</div>
<div class="7 hide" id="lsList">
<p>List of landscapes</p>
<?php
echo "The currently selected instance is: $spec_name"; <!-- This
is where I want to use the variable set above using the onclick
functionality. -->
?>
</div>
<div class="7 hide" id="newSpecDetails">
<p>Form for new details</p>
</div>
</fieldset>
</form>
Any thoughts???
No comments:
Post a Comment