Buon pomeriggio,
Ho un problema con un codice js.
In poche parole vorrei togliere i 2 div (risultato_id & risultato_extra) e i rispettivi risultati devono comparire dentro sul div (risultato) . Di seguito allego il codice js + html e poi anche quello della pagina chat.php .
Grazie per la cortese attenzione.
Codice HTML:<script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script> <script type="text/javascript"> var risultato_id = $('#risultato_id').text(); var risultato_extra = $('#risultato_extra').text(); $(document).ready(function() { $("#dimensione").change(function() { var dimensione = $("#dimensione").val(); if (dimensione == "pixel") { $("#width").attr({max:"1000"}); $("#height").attr({max:"1000"}); $("#riga1").replaceWith("<strong id='riga1'> PX</strong>"); $("#riga2").replaceWith("<strong id='riga2'> PX</strong>"); } else if (dimensione == "percentuale") { $("#width").attr({max:"100"}); $("#height").attr({max:"100"}); $("#riga1").replaceWith("<strong id='riga1'> %</strong>"); $("#riga2").replaceWith("<strong id='riga2'> %</strong>"); } }); $(".extra").change(function() { var extras = []; $.each($(".extra option:selected"), function() { extras.push($(this).val()); }); var ris_extra = ":" + extras.join("-"); ($(".extra").val() == "") ? $("#risultato_extra").text("") : $("#risultato_extra").text(ris_extra); }); $(".prova").keyup(function() { var dimensione = $( "#dimensione" ).val(); var width = $('#width').val(); var height = $('#height').val(); var risultato_id = $('#risultato_id').text(); var risultato_extra = $('#risultato_extra').text(); if (dimensione == "pixel") { if (width > 0 && height > 0) { $("#risultato").text("[chat:" + width + ":" + height + risultato_id + risultato_extra + "]"); } else if (width == 0 || height == 0) { $("#risultato").text("ERRORE. DEVI INSERIRE LA GRANDEZZA!"); } else if (width == "" || height == "") { $("#risultato").text("ERRORE. DEVI INSERIRE LA GRANDEZZA!"); } } else if (dimensione == "percentuale") { if (width > 0 && height > 0) { $("#risultato").text("[chat:" + width + "%:" + height + "%" + risultato_id + risultato_extra + "]"); } else if (width == 0 || height == 0) { $("#risultato").text("ERRORE. DEVI INSERIRE LA GRANDEZZA!"); } else if (width == "" || height == "") { $("#risultato").text("ERRORE. DEVI INSERIRE LA GRANDEZZA!"); } } else { $("#risultato").text("ERRORE!"); } }); }); $(function() { $("#chat").keyup(function() { var chatid = $(this).val(); updateTopic(chatid); }); }); function updateTopic(chatid) { $.ajax({ url: 'chat.php', data: {chat:chatid}, method: 'post', dataType: 'html', success: function(data) { $("#risultato_id").text(data); }, error: function() { alert("Chiamata fallita!!!"); } }); } </script> <!-- CODICE HTML --> <select class="dimensione" id="dimensione"> <option value="pixel" selected>Pixel</option> <option value="percentuale">Percentuale</option> </select> <div class="dimension" id="dimension"> <br /><br />Width: <br /> <input type="number" min="0" max="1000" value="" name="width" id="width" class="prova" /><strong id="riga1"> PX</strong> <br /><br />Height:<br /> <input type="number" min="0" max="1000" value="" name="height" id="height" class="prova" /><strong id="riga2"> PX</strong> </div> <br /> <input type="text" name="chat" id="chat"/> CHAT <br /><br /> <select class="extra" multiple="multiple" size="5"> <option value="autologin">Abilita autologin</option> <option value="noradio">Disabilita radio</option> <option value="nosound">Disabilita suoni</option> <option value="nomessages">Non archiviare i vecchi messaggi</option> <option value="transparent">Sfondo trasparente</option> </select> <br /><br /> <div class="risultato_id prova" id="risultato_id"></div> <br /><br /> <div class="risultato_extra prova" id="risultato_extra"></div> <br /><br /> <div class="risultato" id="risultato"></div>
Codice chat.php
Codice PHP:<?php
function chatInfo($chat) {
$chat = preg_replace('/[^A-Za-z0-9_]/','',$chat);
if(empty($chat)) return false;
$id = file_get_contents('http://xat.com/web_gear/chat/roomid.php?d='.$chat);
if($id != '0#' && is_numeric($id)) return array('name' => $chat, 'id' => $id);
else {// then it's not a "numeric chat"
$res = @file_get_contents('http://xat.com/chat/room/'.$chat.'/?'.time());
if(!$res || !stripos($res,'uname=\'')) return false;
$posLeft = stripos($res, 'uname=\'') + strlen('uname=\'');
$posRight = stripos($res, '\';', $posLeft);
$chatName = substr($res, $posLeft, $posRight - $posLeft);
if(empty($chatName) || strlen($chatName > 50)) return false;
return array('name' => ($chatName == 'chat/room/'.$chat.'/')?'xat'.$chat:$chatName, 'id' => $chat);
}
}
$chat = $_POST['chat'];
$chat = chatInfo($chat);
if(is_array($chat)) {
echo ":" .$chat['id']. ":" .$chat['name'];
}
else {
echo " ERRORE! ";
}
?>

LinkBack URL
About LinkBacks
