2014-09-26 36 views
5

Prima, ho un modulo con un pulsante di opzione e, naturalmente, invia il valore nel pulsante di opzione quando si preme invio.

ma come faccio se non desidero più i pulsanti di opzione? Quando si preme la cella o la riga della tabella, si invierà automaticamente il valore alla pagina successiva senza il pulsante di invio?

<form method="post" action="billing.php"> 
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'> 
     <tr> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td> 
      <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td> 
      <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p> 
       <div id='price'> Additional ₱250 </div></td> 

     </tr> 
     <tr> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td> 
      <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td> 
      <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p> 
       <div id='price'> Free!! </div></td> 
     </tr> 
    </table> 
</form> 

Come faccio essa sottoponga senza utilizzare il pulsante o il pulsante di opzione presentare, per quando si preme il fila, essa sostiene il valore alla pagina successiva e vado alla pagina successiva.

grazie

MODIFICA.

<table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='centerdown'> 
    <tr> 
     <td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="BPI") echo "checked";?> value="BPI"></td> 
     <td><img src="../paymentoptions/BPI.jpg"></td> 
     <td><p>Pay by BPI bank deposit (we need confirmation of payment through email.)<p></td> 
    </tr> 

    <tr> 
     <td><input type="radio" name="payment" <?php if (isset($payment) && $payment=="PickUp") echo "checked";?> value="PickUp"></td> 
     <td><img src="../paymentoptions/Pick-up.jpg"></td> 
     <td><p>Pick up. You have 5 days reservation period. You pay for the merchandise upon pick-up<p></td> 
    </tr> 
</table> 
+0

quindi utilizzare javascript (jquery tagged) per attivare l'invio su riga fare clic su – Ghost

+0

come si fa? –

+0

Questo [http://stackoverflow.com/questions/26014630/submit-form-with-jquery-by-click-on-table-cell) aiuta? – ForguesR

risposta

2

Basta usare le righe per inviarlo. Considerate questo markup:

<form method="post" action="billing.php"> 
    <table width="900" border="0" align="center" cellpadding="2" cellspacing="0" id='center'> 
     <tr class="row_submit"> 
       <!-- ^^ simple class assignment --> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="LBC") echo "checked";?> value="LBC"></td> 
      <td><img src="../paymentoptions/LBC.jpg" alt="LBC" class="picture"/></td> 
      <td><p>The Shipping takes 1-2 days for NCR and 2-3 days for any provincial. Payment method only available is through BPI Bank Deposit<p> 
       <div id='price'> Additional ₱250 </div></td> 

     </tr> 
     <tr class="row_submit"> 
      <td><input type="radio" name="carrier" <?php if (isset($carrier) && $carrier=="PickUp") echo "checked";?> value="PickUp"></td> 
      <td><img src="../paymentoptions/Pick-up.jpg" alt="Pick-Up" class="picture"/></td> 
      <td><p>Personally pick up your merchandise at our office. Free of Charge. Office hours: 10:00 am to 5:00 pm<p> 
       <div id='price'> Free!! </div></td> 
     </tr> 
    </table> 
</form> 

poi sulla vostra JS:

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
<script type="text/javascript"> 
$(document).ready(function(){ 
    $('tr.row_submit').on('click', function(e){ 
     $('form').submit(); 
    }); 
}); 
</script> 

Poi su PHP:

$info_table = array(
    'LBC' => array(
     'price' => 250, 
     'payment' => 'BPI', 
    ), 
    'PickUp' => array(
     'price' => 0, 
     'payment' => '', 
    ), 
); 

if(isset($_POST['carrier'])){ 
    echo $_POST['carrier']; 
    $price = $info_table[$_POST['carrier']]['price']; 
    $payment = $info_table[$_POST['carrier']]['payment']; 
    echo '<br/>' . $price . '<br/>'; 
    echo $payment; 
} 
+0

Giusto per chiarire poiché sembra che l'OP sia nuovo per PHP/Web. Dovresti leggere su come disinfettare i tuoi input e non usare direttamente la variabile $ _POST, altrimenti questo è il modo giusto per farlo – DaOgre

+2

@DaOgre se vogliamo preparare le affermazioni, certo che, naturalmente, questo è tutto un altro argomento , diventerà troppo lungo, ma ovviamente capisco la tua preoccupazione – Ghost

+0

Oh, ha funzionato. hehe. Grazie. Hmm. Come posso inserire 2 valori quando si utilizza questo? perché ho anche bisogno di $ pagamento e $ vettore da presentare, non è incluso nel codice. Questo è il motivo per cui non mi piace usare il pulsante di opzione perché solo 1 può essere inviato o ho sbagliato? grazie. –

0

provare questo:

<script type="text/javascript"> 
    function submit(){ 
     var data = $("form[action=billing.php]").serialize(); 
     $.ajax({ 
      url: "billing.php", 
      type: "POST", 
      data: data, 
      success: function(out){ 
       $(body).html(out); 
      } 
     }); 
    } 
$(document).ready(function(){ 
$('tr.row_submit').click(function(){submit();}); 
} 

</script> 

Vorrei che lavoro S!

+0

Espandi la tua risposta per spiegare cosa fa il tuo codice.Teach OP to fish :) – dimo414

+0

@ dimo414 Seleziona l'elemento form di fatturazione e serializza i suoi input in questo modo carrier = value quindi invia questo modulo via xhr dopo aver cliccato su tr con la classe 'row_submit', infine il corpo del documento verrà aggiornato con il modulo di risposta – majicson

Problemi correlati