Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda com botão editar


Sergio Mendes Borges

Pergunta

9 respostass a esta questão

Posts Recomendados

  • 0

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Cadastro De Usuarios</title>

<link rel="stylesheet" media="all" type="text/css" href="css/style.css"/>

<style type="text/css">

body,td,th {

color: #CCC;

}

</style>

</head>

<body class="bodyColor">

<div class="logo" align="center"><img src="img/logo3.png" width="247" height="36" /></div>

<form id="form">

<div class="conteudo" align="center">

<center>

<table>

<tr height="30px">

</tr>

<tr>

<td width="45">

<label class="textLabel"> Nome: </label>

</td>

<td colspan="3">

<input class="textField" id="nome"/>

</td>

<td>

</td>

<td>

</td>

</tr>

<tr>

<td width="45">

<label class="textLabel"> E-mail: </label>

</td>

<td colspan="3">

<input class="textField" id="email"/>

</td>

<td>

</td>

<td>

</td>

</tr>

<tr height="10px">

<td>

</td>

</tr>

<tr>

<td width="45">

<label class="textLabel"> Senha: </label>

</td>

<td colspan="3">

<input type="password" class="textField" id="senha"/>

</td>

<td>

</td>

<td>

</td>

</tr>

<tr height="10px">

<td>

</td>

</tr>

<tr> <div class="button" align="center">

<td colspan="2" align="right">

<button class="button" onclick="save();" type="button">Salvar</button>

</td>

<td>

</td>

<td colspan="2" align="center">

<button class="button" onclick="cancel();" type="reset">Cancelar</button>

</td>

<td>

</td>

</div>

</tr>

<tr height="20px">

<td>

</td>

</tr>

</table>

<?

include("php/conexao.php");

$sql = mysql_query("SELECT * FROM usuario ORDER BY nome");

$cont = 0;

?>

<div style="overflow:auto; height:250px; width:900px; border-style:solid; border-width:0px;" >

<table align="center" width="800" border="1" cellpadding="0" cellspacing="0" bordercolor="#666666">

<tr>

<td class="tableHeader"> Nome </td>

<td class="tableHeader"> E-mail </td>

<td class="tableHeader" width="30"> </td>

<td class="tableHeader" width="30"> </td>

</tr>

<?

while($dados = mysql_fetch_array($sql)){

if($cont % 2 == 0){ ?>

<tr <? echo "bgcolor='#D3DBF8'";?>>

<td> <font color="#000000"> <? echo $dados["nome"] ?> </font></td>

<td> <font color=#000000"> <? echo $dados["email] ?> </font></td>

<td align="center" width="30">

<a href="#dialog" onclick="remove(<? echo $dados["id"] ?>)">

<img src=img/delete.png" width="21" height="16" alt="Rastreamento" border="0" style='border:0px;padding:1px;'/>

<td align="center" width="30">

<a href="#dialog" onclick="Edit('value from a text column here')">

<img src="img/A_EditInDesigner_Lg_N.png" width="21" height="16" alt="Rastreamento" border="0" style='border:0px;padding:1px;'/>

</td></a>

</tr>

</td>

</tr>

</div>

<?

} else{

?>

<tr <? echo "bgcolor='#ECEBFE'";?> >

<td> <font color="#000000"><? echo $dados["nome] ?> </font></td>

<td><font color="#000000"> <? echo $dados["email"] ?> </font></td>

<td align=center">

</td>

</tr>

<?

}

$cont++;

}

?>

</table>

</div>

</center>

</div>

</form>

</body>

</html>

&lt;script type="text/javascript" language="javascript">

function save(){

if(validaForm()){

var nome = document.getElementById("nome").value;

var email = document.getElementById("email").value;

var senha = document.getElementById("senha").value;

enviaForm(nome, email, senha);

}

}

function validaForm(){

if(document.getElementById("nome").value == ""){

alert("Preencha o campo nome");

document.getElementById("nome").focus;

return false;

}

if(document.getElementById("email").value == ""){

alert("Preencha o campo email");

document.getElementById("email").focus;

return false;

}

if(document.getElementById("senha").value == ""){

alert("Preencha o campo senha");

document.getElementById("senha").focus;

return false;

}

if(!validar()){

return false;

}

return true;

}

function enviaForm(nome, email, senha){

if(window.XMLHttpRequest) {

req = new XMLHttpRequest();

} else if(window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

req.open("Get", "php/validaMorador.php?nome=" + nome + "&email=" + email + "&senha=" + senha, true);

req.onreadystatechange = function() {

if(req.readyState == 4 && req.status == 200) {

var resposta = -3;

resposta = req.responseText;

if(resposta == 0){

//Valido com solicitação de peças

alert("Cadastro realizado com sucesso!");

window.location="cadastro.php";

} else if(resposta == -1){

//Valido mas sem solicitação de peças

alert("Erro desconhecido!");

} else if(resposta == -2){

alert("Usuário já existente!");

}

}

}

req.send(null);

}

function remove(id){

var decisao = confirm("Tem certeza que deseja excluir este usuário?");

//OK

if (decisao){

if(window.XMLHttpRequest) {

req = new XMLHttpRequest();

} else if(window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

req.open("Get", "php/removeusuario.php?id=" + id, true);

req.onreadystatechange = function() {

if(req.readyState == 4 && req.status == 200) {

window.location="cadastro.php";

}

}

req.send(null);

}

}

function validar(){

var str = document.getElementById('email').value;

var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

if(filter.test(str)){

return true;

} else{

alert("Este endereço de e-mail não é válido!");

document.cadastro.E-mail.focus();

return false;

}

}

//editei

function edita(id){

//OK

if(window.XMLHttpRequest) {

req = new XMLHttpRequest();

} else if(window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

req.open("Get", "php/seleciona.php?id=" + id, true);

req.onreadystatechange = function() {

if(req.readyState == 4 && req.status == 200) {

window.location="cadastro.php";

}

}

}

</script>

quero fazer a funcao edita....

seleciona.php

<?

include("conexao.php");

$id = $_GET['id];

$sql = mysql_query("SELECT * FROM usuario WHERE 'id' = $id");

$dados = mysql_fetch_array($sql);

?>

Link para o comentário
Compartilhar em outros sites

  • 0

O edit e uma imagem ..

amigo

so não sei porque ela não ta funcionando

<td align="center" width="30">

<a href="#dialog" onclick="Edit('value from a text column here')">

<img src="img/A_EditInDesigner_Lg_N.png" width="21" height="16" alt="Rastreamento" border="0" style='border:0px;padding:1px;'/>

</td></a>

Link para o comentário
Compartilhar em outros sites

  • 0

Claro que não vai funcionar. Presta atenção na lógica, qual parâmetro você está passando para o botão?

<a href="#dialog" onclick="Edit('value from a text column here')">
o único vai passado é 'value from a text column here': Veja como está chamando a função javascritp remove() você está passando o ID
<a href="#dialog" onclick="remove(<? echo $dados["id"] ?>)">
então o certo seria:
<a href="#dialog" onclick="Edit(<? echo $dados["id"] ?>)">

Tenta ae e veja o resultado.

Editado por Ricardo T. do Prado
Link para o comentário
Compartilhar em outros sites

  • 0

Sérgio,

Fica dificil eu resolver todos seus problemas. Acho que você não está analisando o código corretamente, ou não tem conhecimento. Observe a função baixo:

//editei

function edita(id){

//OK

if(window.XMLHttpRequest) {

req = new XMLHttpRequest();

} else if(window.ActiveXObject) {

req = new ActiveXObject("Microsoft.XMLHTTP");

}

req.open("Get", "php/seleciona.php?id=" + id, true);

req.onreadystatechange = function() {

if(req.readyState == 4 && req.status == 200) {

window.location="cadastro.php";

}

}

}

</script>

Ela pega a ID e passa por parâmetro para a pagina "seleciona.php", e depois tem um "window.location" redirecionando para "cadastro.php". Ou seja, ele passa os parâmetros, executa os scripts da pagina chamada, e dpois retorna automaticamente para a página informada.

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...