Search code examples
javahtmljsfhtml-selectjavabeans

how to modify my page and pass my selected option to java beans


i am using html code to display my page depending on the selected option i click on. But now i want to pass my selected choice to java beans too.

my 4 options

<tr>
<td class="title">Category:</td>
<td class="field">
    <select name="list" onchange="display(this,'truck','car');">
    <option>Please select:</option>
    <option value="invisible">Bike</option>
    <option value="invisible">Quad</option>
    <option value="car">Car</option>
    <option value="truck">Truck</option>
    </select>
</td>
</tr>

Script i am using

<script type="text/javascript">
function display(obj,id1,id2) {
    txt = obj.options[obj.selectedIndex].value;
    document.getElementById(id1).style.display = 'none';
    document.getElementById(id2).style.display = 'none';
    if ( txt.match(id1) ) {
        document.getElementById(id1).style.display = 'block';
    }
    if ( txt.match(id2) ) {
        document.getElementById(id2).style.display = 'block';
    }
}

</script>

display function is modifying my page doing the following:

<tbody id="car" style="display: none;">

and

<tbody id="truck" style="display: none;">

Now, how do i pass my selected options to java beans?


Solution

  • Use AJAX. That allows you to send data to the server without changing anything on the web page.

    Try a framework like jQuery which offers AJAX (docs) and a lot of other cool stuff to build HTML5 applications.