Juan Esteban
Juan Esteban

Reputation: 1

Delete Blank option Jquery and PHP

I need to remove the blank option.

This is a restaurant web page and this is the reservation form. The thing is that they are reciving a lot of "blank" reservation hours because people don't specify the reservation hour.

Sorry for my English, I'm from Spain :)

Image

The code:

HTML read by browser

    <div id="lashoras">
                                <select name="Hora" size="1" onChange="updateHoraPersonas();">
    <option value="" selected="selected"> </option>
<option value="1330">13:30</option>
    <option value="1400">14:00</option>
    <option value="1430">14:30</option>
    <option value="1500">15:00</option>
    <option value="1930">19:30</option>
    <option value="2000">20:00</option>
    <option value="2030">20:30</option>
    <option value="2100">21:00</option>
    <option value="2130">21:30</option><option value="2200">22:00</option></select>                     
                                </div>

source code HTML

<div id="lashoras">
                        <?php
                         echo $selectFullDay;
                        ?>

SelectFullDay PHP Var

$selectFullDay = build_select_options ("Hora","id_lookup","lookup","lookups",0," ",$onChange,$theWhere,$multiple,$orderby);

updateHoraPersonas Function

function updateHoraPersonas(){
    var mediodiaMax = maxPersonas;
    var nocheMax = maxPersonas;

    mediodiaMax = maxPersonas-curDia_mediodia_reservados;
    if(mediodiaMax<0) mediodiaMax = 0;

    nocheMax = maxPersonas-curDia_noche_reservados;
    if(nocheMax<0) nocheMax = 0;

    var hora = $('#lashoras').val();
    //hora blank for first, otherwise 1330

    //primero ver si llegado a tope de mediodia/noche
    if (hora <= horaCambio) {
        selectMax = mediodiaMax;
    } else {
        selectMax = nocheMax;
    }

    //y ahora hora a hora
    selectMax = Math.min(selectMax,horasArray[hora]);

    var Numero_de_personasSelect = "";
    for (i=1 ; i<= selectMax ; i++) {
        if (i==1) {
            selected = "selected='selected'";
        } else {
            selected = "";
        }


        Numero_de_personasSelect += "<option value='"+i+"' "+selected+" >"+i+"</option>";
    }

    if (selectMax <=0 ) {
        Numero_de_personasSelect += "<option value=''>Completo</option>";
    }

    $("#Numero_de_personas").html(Numero_de_personasSelect);


    //alert('mediodiaMax: '+mediodiaMax+' | nocheMax: '+nocheMax+' | selectMax: '+selectMax);}

</script>

....

Upvotes: 0

Views: 48

Answers (1)

Krishanu
Krishanu

Reputation: 562

Change the form submission so that the user cannot submit if the reservation time is not specified! This way you processing time does not increase on explicitly removing blank options

an exapmle

<?php
if(!isset($_POST['time'])){
  //'Enter valid details
}else{
  //redirect here
}

Upvotes: 1

Related Questions