2017-07-13 3 views
0
geklickt wird

ich mit php.I lernen jquery beginnen werde habe Form (die ich von Google kopiert)Wie der Wert der Textbox auf 0, wenn leer setzen, wenn Checkbox nicht

$('document').ready(function() { 
 
    $('.toggleswitch').bootstrapToggle(); 
 
    $("#check1 .stars").click(function() { 
 
    $(this).attr("checked"); 
 
    }); 
 

 
});
/****** Rating Starts *****/ 
 

 
@import url(http://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); 
 
fieldset, 
 
label { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
body { 
 
    margin: 20px; 
 
} 
 

 
h1 { 
 
    font-size: 1.5em; 
 
    margin: 10px; 
 
} 
 

 
.rating { 
 
    border: none; 
 
    float: left; 
 
} 
 

 
.rating>input { 
 
    display: none; 
 
} 
 

 
.rating>label:before { 
 
    margin: 5px; 
 
    font-size: 1.25em; 
 
    font-family: FontAwesome; 
 
    display: inline-block; 
 
    content: "\f005"; 
 
} 
 

 
.rating>.half:before { 
 
    content: "\f089"; 
 
    position: absolute; 
 
} 
 

 
.rating>label { 
 
    color: #ddd; 
 
    float: right; 
 
} 
 

 
.rating>input:checked~label, 
 
.rating:not(:checked)>label:hover, 
 
.rating:not(:checked)>label:hover~label { 
 
    color: #FFD700; 
 
} 
 

 
.rating>input:checked+label:hover, 
 
.rating>input:checked~label:hover, 
 
.rating>label:hover~input:checked~label, 
 
.rating>input:checked~label:hover~label { 
 
    color: #FFED85; 
 
} 
 

 

 
/* Downloaded from http://devzone.co.in/ */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" /> 
 
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" /> 
 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-toggle/2.2.2/js/bootstrap2-toggle.min.js"></script> 
 
<form action="" method="POST" /> 
 
<fieldset id='check1' class="rating"> 
 
    <input class="stars" type="radio" id="star_a-5" name="rating" value="5" /> 
 
    <label class="full" for="star5" title="Awesome - 5 stars"></label> 
 
    <input class="stars" type="radio" id="star_a_5-half" name="rating" value="4.5" /> 
 
    <label class="half" for="star4half" title="Pretty good - 4.5 stars"></label> 
 
    <input class="stars" type="radio" id="star_a-4" name="rating" value="4" /> 
 
    <label class="full" for="star4" title="Pretty good - 4 stars"></label> 
 
    <input class="stars" type="radio" id="star_a_4-half" name="rating" value="3.5" /> 
 
    <label class="half" for="star3half" title="Meh - 3.5 stars"></label> 
 
    <input class="stars" type="radio" id="star_a-3" name="rating" value="3" /> 
 
    <label class="full" for="star3" title="Meh - 3 stars"></label> 
 
    <input class="stars" type="radio" id="star_a_3-half" name="rating" value="2.5" /> 
 
    <label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label> 
 
    <input class="stars" type="radio" id="star2" name="rating" value="2" /> 
 
    <label class="full" for="star2" title="Kinda bad - 2 stars"></label> 
 
    <input class="stars" type="radio" id="star1half" name="rating" value="1.5" /> 
 
    <label class="half" for="star1half" title="Meh - 1.5 stars"></label> 
 
    <input class="stars" type="radio" id="star1" name="rating" value="1" /> 
 
    <label class="full" for="star1" title="Sucks big time - 1 star"></label> 
 
    <input class="stars" type="radio" id="starhalf" name="rating" value="0.5" /> 
 
    <label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label> 
 
</fieldset> 
 
<br> 
 

 
<input type="submit" onclick="setValue()" name="btn_submit" value="submit" /> 
 
</div>

mit dieser PHP:

<?php 
if(isset($_POST['btn_submit'])) 
{ 
    echo '<pre>'; 
    print_r($_POST); 
} 

?> 

Diese Form fine.If funktioniert i-Sterne-Rate klicken und Absenden-Button habe ich eine Ausgabe wie

Array 
(
    [rating] => 1 
    [btn_submit] => submit 
) 

Und wenn ich wählen werde keine Bewertung Ausgabe wie sein

Array 
    (

     [btn_submit] => submit 
    ) 

aber ich erwarte

Array 
     (
      [rating] => 0 
      [btn_submit] => submit 
     ) 

Ich versuchte

function setValue() 
     { 
      var input = document.getElementById('check1'); 

    if(input.value.length == '') 
    input.value = 0; 
     } 

Wenn ich nicht bin klicken Sterne Rate Eingabefeld auf 0 gesetzt? Wie kann ich tun, wenn ich mehr Texteingabe wie check2 PRÜFUNG3Haben check4 mit jquery? Ich habe wollen, dass alle Eingabetextfeld gesetzt als 0, bevor Daten gesendet, wenn Bewertung mir nicht clicked.Please helfen ist? Als Anfänger vergeben Sie bitte, ob macht jede hatte Fehler

+0

Wenn Sie keine Checkbox wird es nicht Wert des Servers bereitstellen Seite –

+0

@PankajMakwana: Dann wie kann ich it..please mir helfen .. –

+0

@teststack ich habe eine [Antwort] (https://stackoverflow.com/a/45079490/4939819) – Hassaan

Antwort

1

Dies wird nicht als Parameter an den Server zu senden, wenn Sie irgendeine Kästchen

Additionaly nicht überprüfen Sie in PHP-Dateien überprüfen können, dh es geschrieben ist oder nicht.

Versuchen

if(isset($_POST['btn_submit'])) 
{ 
    $_POST['rating'] = isset($_POST['rating']) ? $_POST['rating'] : '0'; 
    echo '<pre>'; 
    print_r($_POST); 
+0

@ Hassan-Danke für Ihre beantworten, aber ich will es prüfen mit jquery? ist es möglich, –

+0

@teststack Versuchen 'Eingang zu ersetzen.Wert = 0; 'mit' $ ('input # check1'). val ('0'); ' – Hassaan

1

nur Bedingung hinzufügen zuerst in PHP wie unten

if(!isset($_POST['rating'])){ 
    $_POST['rating'] = 0; 
} 
print_r($_POST); 
1

Sie die nicht Schaltfläche einreichen um den Wert zu überprüfen - setzen stattdessen den Wert und die Benutzer den Absenden-Ereignis des Formulars zu überprüfen

Ich musste auch das bootstrap, das nicht verwendet wurde, UND ändern Sie die IDs der Funkgeräte

Wenn Sie den Server, wurde festgelegt, dass einreichen überprüfen müssen schlagen aber kein Radio weitergegeben. Dann das bedeutet 0 - jetzt mein jQuery nicht Vorlage zulassen, wenn nicht bewertet - gab ich die Form eine ID

$('document').ready(function() { 
 
    $("#myForm").on("submit",function(e) { 
 
    if($("#check1 .stars:checked").length==0) { 
 
     alert("Please rate"); 
 
     e.preventDefault(); 
 
    } 
 
    }) 
 
});
/****** Rating Starts *****/ 
 
@import url(https://netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css); 
 

 
fieldset, 
 
label { 
 
    margin: 0; 
 
    padding: 0; 
 
} 
 

 
body { 
 
    margin: 20px; 
 
} 
 

 
h1 { 
 
    font-size: 1.5em; 
 
    margin: 10px; 
 
} 
 

 
.rating { 
 
    border: none; 
 
    float: left; 
 
} 
 

 
.rating>input { 
 
    display: none; 
 
} 
 

 
.rating>label:before { 
 
    margin: 5px; 
 
    font-size: 1.25em; 
 
    font-family: FontAwesome; 
 
    display: inline-block; 
 
    content: "\f005"; 
 
} 
 

 
.rating>.half:before { 
 
    content: "\f089"; 
 
    position: absolute; 
 
} 
 

 
.rating>label { 
 
    color: #ddd; 
 
    float: right; 
 
} 
 

 
.rating>input:checked~label, 
 
.rating:not(:checked)>label:hover, 
 
.rating:not(:checked)>label:hover~label { 
 
    color: #FFD700; 
 
} 
 

 
.rating>input:checked+label:hover, 
 
.rating>input:checked~label:hover, 
 
.rating>label:hover~input:checked~label, 
 
.rating>input:checked~label:hover~label { 
 
    color: #FFED85; 
 
} 
 

 

 
/* Downloaded from http://devzone.co.in/ */
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> 
 

 
<form id="myForm" action="" method="POST" /> 
 
<fieldset id='check1' class="rating toggleswitch"> 
 
    <input class="stars" type="radio" id="star5" name="rating" value="5" data-toggle="toggle"/> 
 
    <label class="full" for="star5" title="Awesome - 5 stars"></label> 
 
    <input class="stars" type="radio" id="star4half" name="rating" value="4.5" data-toggle="toggle"/> 
 
    <label class="half" for="star4half" title="Pretty good - 4.5 stars"></label> 
 
    <input class="stars" type="radio" id="star4" name="rating" value="4" data-toggle="toggle"/> 
 
    <label class="full" for="star4" title="Pretty good - 4 stars"></label> 
 
    <input class="stars" type="radio" id="star3half" name="rating" value="3.5" data-toggle="toggle"/> 
 
    <label class="half" for="star3half" title="Meh - 3.5 stars"></label> 
 
    <input class="stars" type="radio" id="star3" name="rating" value="3" data-toggle="toggle"/> 
 
    <label class="full" for="star3" title="Meh - 3 stars"></label> 
 
    <input class="stars" type="radio" id="star2half" name="rating" value="2.5" data-toggle="toggle"/> 
 
    <label class="half" for="star2half" title="Kinda bad - 2.5 stars"></label> 
 
    <input class="stars" type="radio" id="star2" name="rating" value="2" /> 
 
    <label class="full" for="star2" title="Kinda bad - 2 stars"></label> 
 
    <input class="stars" type="radio" id="star1half" name="rating" value="1.5" data-toggle="toggle"/> 
 
    <label class="half" for="star1half" title="Meh - 1.5 stars"></label> 
 
    <input class="stars" type="radio" id="star1" name="rating" value="1" data-toggle="toggle" /> 
 
    <label class="full" for="star1" title="Sucks big time - 1 star"></label> 
 
    <input class="stars" type="radio" id="starhalf" name="rating" value="0.5" data-toggle="toggle"/> 
 
    <label class="half" for="starhalf" title="Sucks big time - 0.5 stars"></label> 
 
</fieldset> 
 
<br> 
 

 
<input type="submit" name="btn_submit" value="submit" /> 
 
</div>

Verwandte Themen