IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

Récupérer la valeur de mon id


Sujet :

jQuery

  1. #1
    Nouveau membre du Club
    Inscrit en
    Novembre 2013
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Novembre 2013
    Messages : 6
    Par défaut Récupérer la valeur de mon id
    Bonjour tout le monde,

    Je suis nouveau sur ce forum suite a avoir fait pas mal de recherche sur mon problème mais rien de bien positive donc je viens demandé en aide.

    je suis un peu beaucoup perdu sur la façon de récupérer la valeur de mon span en php qui change en fonction des bonus choisis. je vous montre mon code pour plus de détails.

    Mon code html correspond à ceci (le 0 sur la page chargée change en fonction des bonus choisis sans rafraichir la page)
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <span style="color:#090;" id="cost_prem" name="cost_prem">0</span> DM:</td>

    Mon code js correspond a ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $('#cost_prem').text(Math.round(Number(skidka_price)* (Number(count_day))*(prem_s_build_price+prem_o_build_price+prem_button_price+prem_leveling_price+prem_bank_ally_price)));
    et mon code php correspond a cela
    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    $cost_prem   = HTTP::_GP('cost_prem', 0);

    Le seul souci ses qu'avec ses codes là, il me retourne à chaque fois la valeur 0
    si quelqu'un pouvait me venir en aide.

  2. #2
    Expert confirmé
    Avatar de Watilin
    Homme Profil pro
    En recherche d'emploi
    Inscrit en
    Juin 2010
    Messages
    3 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : En recherche d'emploi

    Informations forums :
    Inscription : Juin 2010
    Messages : 3 100
    Par défaut
    Bonsoir !

    Pour qu'on puisse t'aider, il faudrait que tu nous en dises plus. Il y a plein de variables dans ton code JavaScript (skidka_price, count_day, prem_s_build_price, prem_o_build_price, prem_button_price, prem_leveling_price, prem_bank_ally_price), on ne sait pas où elles sont définies, quelles valeurs elles contiennent, etc. As-tu essayé un débogage pas-à-pas avec une console JavaScript ? (touche F12)

    Pour l'instant, tout ce que je peux te dire c'est que la partie $("#cost_prem").text( est correcte.

    Pareil dans ton code PHP, je ne sais pas ce que fait HTTP:_GP. J'ai dans l'idée que ça fait partie d'un framework (si oui, lequel ?) et que ça te permet de récupérer les paramètres GET et POST. Si cost_prem est un paramètre GET, tu peux le récupérer directement en JavaScript grâce à location.search.

    Pour finir, une petite remarque : un attribut name sur un <span>, ça ne sert à rien…
    La FAQ JavaScript – Les cours JavaScript
    Touche F12 = la console → l’outil indispensable pour développer en JavaScript !

  3. #3
    Nouveau membre du Club
    Inscrit en
    Novembre 2013
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Novembre 2013
    Messages : 6
    Par défaut
    Bonjour Watilin.

    toutes les variable que tu ma ecrite sont des simple calcul.

    du nombre choisi par l'utilisateur * 17

    count_day = de 1 a 100 au choix de l'utilisateur

    et skida_price = une diminution du cout total si tu achete pour une durée plus longue que 7 jour

    par defaukt skida_price = 1 ensuite 0.95

    En principe j'utilise du $_POST ou $_GET en php mais ca ne fonctionne pas dans ce cas si? peut etre a cause du smarty tpl?

    Pour le name dans le span, je m'en etait rendu compte et je l'ai supprimer.

  4. #4
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut
    Déjà tu dis avoir un pb JS et tu poste un bout de JQuery
    ne te serais-tu pas trompé de forum ?

    ensuite je ne vois à aucun moment un appel ajax un post ou un href
    tu n'appelle donc jamais ton php
    comment dans ce cas peux-tu essayer de récupérer une valeur par GET ou POST

    A+JYT

  5. #5
    Nouveau membre du Club
    Inscrit en
    Novembre 2013
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Novembre 2013
    Messages : 6
    Par défaut
    Je vais mettre mon fichier .tpl au complet si ca peu aider

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    {block name="title" prepend}Become Premium{/block}
    {block name="content"}
     <div id="content">
    <script type="text/javascript" src="./scripts/game/prem.js"></script>
    <table class="table519" width="500px" style="width:500px !important;">
    <tbody>
    	<tr>
    		<td style="text-align:left;">
    			<span style="margin-left:3px; color:#FF0000">Premium account:<b style="color:#CCCCCC" id=brpstats></b></span>
        	</td>
        </tr>
        <tr>
            <th>Setting up bonus premium account:</th>
        </tr>
    	<tr>
            <td style="text-align:left;">
     
                <input type="hidden" name="mode" value="send" >
     
            	<table style="width:90%;">
    			<form method="POST">
     
                	<tr>
                        <th colspan="2" class="tooltip" data-tooltip-content="In parentheses is shown as increased bonus.<br />The speed of construction and research <font color=lime>min 100%(+50%)</font> <font color=Yellow> max 1000%</font>, <br />Stage of construction and research <font color=lime>min 2(+1)</font> <font color=Yellow> max 10</font>, <br />daily bonus <font color=lime>min x2(+1)</font> <font color=Yellow> max x10</font>, <br />Bonus DM (Dark Matter Search)  <font color=lime>min 50%(+5%)</font> <font color=Yellow>max 150%</font>, <br />Number Earn experience <font color=lime>min 30%(+5%)</font> <font color=Yellow>max 120%</font>">bonus || FAQ </th>
    					<th>current</th>
    					<th class="tooltip" data-tooltip-content="The minimum bonus has already been put! <br />The minimum bonus is exhibited if you do not need neck. set bonuses: <br /> The speed of construction and research <font color=lime>+0%</font>, <br />Stage of construction and research<font color=lime>+0</font>, <br />daily bonus <font color=lime>x0</font>, <br />Bonus DM (Dark Matter Search) <font color=lime>+0%</font>, <br />Number Earn experience <font color=lime>+0%</font>, ">establish||FAQ</th>
     
                    </tr>
     
                    <tr>
                    	<td>The speed of construction and research</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает скорость строительства <br /> построек и скорость исследования"></td><td><span style="color:#00FF00; font-weight:bold">+{$bonus1}%</span></td>
                        <td>+<input style="width:50px;" type="text" value="25" id="prem_s_build" name="prem_s_build" onkeyup="Totalo();">%</td>
                    </tr>
                    <tr>
                    	<td>The number of "DM Exploration"</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Дает возможность добавлять больше <br /> исследований и построек в очередь"></td><td><span style="color:#00FF00; font-weight:bold">+{$bonus2}</span></td>
                        <td>+<input style="width:50px;" type="text" value="5" id="prem_o_build" name="prem_o_build" onkeyup="Totalo();">&nbsp;&nbsp;</td>
                    </tr>
                    <tr>
                    	<td>The "Fleeter" and "Turtle" bonus</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает размер получемого бонуса"></td><td><span style="color:#00FF00; font-weight:bold">+{$bonus3}%</span></td>
                        <td>+<input style="width:50px;" type="text" value="30" id="prem_button" name="prem_button" onkeyup="Totalo();">%</td>
                    </tr>
                    <tr>
                    <tr>
                    	<td>The amount of experience earn</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает количество зарабатываемых <br /> очков для академии за бой."></td><td><span style="color:#00FF00; font-weight:bold">+{$bonus4}%</span></td>
                        <td>+<input style="width:50px;" type="text" value="50" id="prem_leveling" name="prem_leveling" onkeyup="Totalo();">%</td>
                    </tr>
                    <tr>
                    	<td>The amount of ships from active players events.</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает максимальное количество <br /> передаваемых ресурсов за раз в банке альянса"></td><td><span style="color:#00FF00; font-weight:bold">+{$bonus5}%</span></td>
                        <td>+<input style="width:50px;" type="text" value="10" id="prem_bank_ally" name="prem_bank_ally" onkeyup="Totalo();">%</td>
                    </tr>
                    				        <tr>
                    	<td colspan="2" style="text-align:right;">cost 
    					<span style="color:#090;" id="cost_prem" name="cost_prem">0</span> DM:</td>
                    	<td><input style="width:50px;"  type="text" size="3" value="0" id="count_day" name="count_day" onkeyup="Totalo();"></td>
                        <td><input type="submit" style="width:70px;" name="Buy" value="buy"></td>
                    </tr>
    								</form>
                </table>
            </td>
        </tr>
       </tbody>
    </table>
     
    </div>
    {/block}

    et voici mon php

    Code php : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    <?php
     
    class ShowBuyPremiumPage extends AbstractPage
    {
     
    	function __construct() 
    	{
    		parent::__construct();
    	}
     
    	function show(){
    		global $USER, $PLANET, $LNG, $UNI, $CONF,$resource,$pricelist;
     
             $prem_s_build   = HTTP::_GP('prem_s_build', 0);
    		 $prem_o_build   = HTTP::_GP('prem_o_build', 0);
    		 $prem_button   = HTTP::_GP('prem_button', 0);
    		 $prem_leveling   = HTTP::_GP('prem_leveling', 0);
    		 $prem_bank_ally   = HTTP::_GP('prem_bank_ally', 0);
    		 $cost_prem   = HTTP::_GP('cost_prem', 0);
    		 $count_day   = HTTP::_GP('count_day', 0);
     
     
                     $bonus1 = 0;
            if($USER['premium_until'] > TIMESTAMP )
    			$bonus1 = $USER['prem_s_build'];
     
                            $bonus2 = 0;
            if($USER['premium_until'] > TIMESTAMP )
    			$bonus2 = $USER['prem_o_build'];
     
                             $bonus3 = 0;
            if($USER['premium_until'] > TIMESTAMP )
    			$bonus3 = $USER['prem_button'];
     
                            $bonus4 = 0;
            if($USER['premium_until'] > TIMESTAMP)
    			$bonus4 = $USER['prem_leveling'];
     
                            $bonus5 = 0;
            if($USER['premium_until'] > TIMESTAMP)
    			$bonus5 = $USER['prem_bank_ally'];
     
    	if($_POST){
     
     
    	//enough dm ? 
    	if($USER['darkmatter'] < 150000){
    		$this->printMessage("Not enough DM", true, array('game.php?page=BuyPremium', 2));
    		die();
    	}
           // if($USER['premium_until'] > TIMESTAMP){
    		//$this->printMessage("You already have premium account", true, array('game.php?page=BuyPremium', 2));
    		//die();
    	 //}
     
    	//seems legit, go forward and see what needs to be done
     
    	//1. remove dm
    	$USER['darkmatter'] -= 150000;
     
    		$GLOBALS['DATABASE']->query("
    			Update
    				".USERS."
    			SET
    				`prem_s_build` = ".$prem_s_build.",
    				`prem_o_build` = ".$prem_o_build.",
    				`prem_button` = ".$prem_button.",
    				`prem_leveling` = ".$prem_leveling.",
    				`prem_bank_ally` = ".$prem_bank_ally.",
    				`premium_until` = ".(TIMESTAMP + $count_day*60*60*24)."
    				
    			WHERE
    				`id` = ".$USER['id']." ;
    		");
                 //   $GLOBALS['DATABASE']->query("INSERT INTO `uni1_premium_lottery` VALUES ('".$USER['id']."','".$USER['username']."','1') ;");
     
    	$this->printMessage($cost_prem, true, array('game.php?page=BuyPremium', 2));
    	die();
     
    	}
    	$this->tplObj->loadscript("jquery.countdown.js");
    		$this->tplObj->assign_vars(
    				array(
                                            'bonus1' => $bonus1,
                                            'bonus2' => $bonus2,
                                            'bonus3' => $bonus3,
                                            'bonus4' => $bonus4,
                                            'bonus5' => $bonus5,
    					'p_state' => (($USER['premium_until'] > TIMESTAMP) ? '' :'<button type="submit" name="Buy">Buy</button>' ),
    					'premium_active' => ((!empty($USER['premium_until']) && $USER['premium_until'] > TIMESTAMP) ? ($USER['premium_until'] - TIMESTAMP) : 0),
    				)
    		);
    		$this->display("page.premium_page.default.tpl");
    	}
    }

    tout le php fonctionne bien exepté la partie pour recuperé la valeur du cost prem.

  6. #6
    Expert confirmé
    Avatar de sekaijin
    Homme Profil pro
    Urbaniste
    Inscrit en
    Juillet 2004
    Messages
    4 205
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 61
    Localisation : France, Yvelines (Île de France)

    Informations professionnelles :
    Activité : Urbaniste
    Secteur : Santé

    Informations forums :
    Inscription : Juillet 2004
    Messages : 4 205
    Par défaut
    Non ce n'est pas le code source du serveur qui nous intéresse mais ce qu'il y a dans ton navigateur

    "afficher la source de la page" dans chrome
    CTRL + U dans FireFox
    etc.

    A+JYT

  7. #7
    Nouveau membre du Club
    Inscrit en
    Novembre 2013
    Messages
    6
    Détails du profil
    Informations forums :
    Inscription : Novembre 2013
    Messages : 6
    Par défaut
    Le code source de ma page ressemble a ceci

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    <div id="content">
    <script type="text/rocketscript" data-rocketsrc="./scripts/game/prem.js"></script>
    <table class="table519" width="500px" style="width:500px !important;">
    <tbody>
    <tr>
    <td style="text-align:left;">
    <span style="margin-left:3px; color:#FF0000">Premium account:<b style="color:#CCCCCC" id=brpstats></b></span>
    </td>
    </tr>
    <tr>
    <th>Setting up bonus premium account:</th>
    </tr>
    <tr>
    <td style="text-align:left;">
    <input type="hidden" name="mode" value="send">
    <table style="width:90%;">
    <form method="POST">
    <tr>
    <th colspan="2" class="tooltip" data-tooltip-content="In parentheses is shown as increased bonus.<br />The speed of construction and research <font color=lime>min 100%(+50%)</font> <font color=Yellow> max 1000%</font>, <br />Stage of construction and research <font color=lime>min 2(+1)</font> <font color=Yellow> max 10</font>, <br />daily bonus <font color=lime>min x2(+1)</font> <font color=Yellow> max x10</font>, <br />Bonus DM (Dark Matter Search)  <font color=lime>min 50%(+5%)</font> <font color=Yellow>max 150%</font>, <br />Number Earn experience <font color=lime>min 30%(+5%)</font> <font color=Yellow>max 120%</font>">bonus || FAQ </th>
    <th>current</th>
    <th class="tooltip" data-tooltip-content="The minimum bonus has already been put! <br />The minimum bonus is exhibited if you do not need neck. set bonuses: <br /> The speed of construction and research <font color=lime>+0%</font>, <br />Stage of construction and research<font color=lime>+0</font>, <br />daily bonus <font color=lime>x0</font>, <br />Bonus DM (Dark Matter Search) <font color=lime>+0%</font>, <br />Number Earn experience <font color=lime>+0%</font>, ">establish||FAQ</th>
    </tr>
    <tr>
    <td>The speed of construction and research</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает скорость строительства <br /> построек и скорость исследования"></td><td><span style="color:#00FF00; font-weight:bold">+25%</span></td>
    <td>+<input style="width:50px;" type="text" value="25" id="prem_s_build" name="prem_s_build" onkeyup="Totalo();">%</td>
    </tr>
    <tr>
    <td>The number of "DM Exploration"</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Дает возможность добавлять больше <br /> исследований и построек в очередь"></td><td><span style="color:#00FF00; font-weight:bold">+5</span></td>
    <td>+<input style="width:50px;" type="text" value="5" id="prem_o_build" name="prem_o_build" onkeyup="Totalo();">&nbsp;&nbsp;</td>
    </tr>
    <tr>
    <td>The "Fleeter" and "Turtle" bonus</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает размер получемого бонуса"></td><td><span style="color:#00FF00; font-weight:bold">+30%</span></td>
    <td>+<input style="width:50px;" type="text" value="30" id="prem_button" name="prem_button" onkeyup="Totalo();">%</td>
    </tr>
    <tr>
    <tr>
    <td>The amount of experience earn</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает количество зарабатываемых <br /> очков для академии за бой."></td><td><span style="color:#00FF00; font-weight:bold">+50%</span></td>
    <td>+<input style="width:50px;" type="text" value="50" id="prem_leveling" name="prem_leveling" onkeyup="Totalo();">%</td>
    </tr>
    <tr>
    <td>The amount of ships from active players events.</td><td><img src="./styles/resource/images/admin/i.gif" width="16" height="16" alt="" class="tooltip" data-tooltip-content="Увеличивает максимальное количество <br /> передаваемых ресурсов за раз в банке альянса"></td><td><span style="color:#00FF00; font-weight:bold">+10%</span></td>
    <td>+<input style="width:50px;" type="text" value="10" id="prem_bank_ally" name="prem_bank_ally" onkeyup="Totalo();">%</td>
    </tr>
    <tr>
    <td colspan="2" style="text-align:right;">cost
    <span style="color:#090;" id="cost_prem" name="cost_prem">0</span> DM:</td>
    <td><input style="width:50px;" type="text" size="3" value="0" id="count_day" name="count_day" onkeyup="Totalo();"></td>
    <td><input type="submit" style="width:70px;" name="Buy" value="buy"></td>
    </tr>
    </form>
    </table>
    </td>
    </tr>
    </tbody>
    </table>
    </div>

    bav

  8. #8
    Expert confirmé
    Avatar de Watilin
    Homme Profil pro
    En recherche d'emploi
    Inscrit en
    Juin 2010
    Messages
    3 100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : France, Ille et Vilaine (Bretagne)

    Informations professionnelles :
    Activité : En recherche d'emploi

    Informations forums :
    Inscription : Juin 2010
    Messages : 3 100
    Par défaut
    Sans vouloir te vexer, tu peux jeter ton template à la poubelle. Une <table> ne doit pas servir pour la mise en page.

    Ensuite, je ne vois qu'un seul script dans le code source généré, et il est bizarre :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <script type="text/rocketscript" data-rocketsrc="./scripts/game/prem.js"></script>
    Aucune chance qu'un navigateur reconnaisse du javascript avec ces attributs. Après une brève recherche, il me semble que rocketscript est lié à un module sur ton serveur, Cloudflare, que tu devras peut-être désactiver. Dans le code généré, ta balise de script doit être comme ça :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <script type="text/javascript" src="./scripts/game/prem.js"></script>
    La FAQ JavaScript – Les cours JavaScript
    Touche F12 = la console → l’outil indispensable pour développer en JavaScript !

Discussions similaires

  1. récupérer les valeurs de mon grid aprés édition
    Par renardchan dans le forum Ext JS / Sencha
    Réponses: 3
    Dernier message: 22/06/2011, 23h10
  2. Récupérer la valeur de mon textarea
    Par vivi21 dans le forum Langage
    Réponses: 3
    Dernier message: 07/01/2011, 10h44
  3. Réponses: 23
    Dernier message: 05/05/2010, 16h59
  4. Réponses: 4
    Dernier message: 22/04/2010, 16h06
  5. [PHP 5.2] Récupèrer la valeur de mon $_POST
    Par beegees dans le forum Langage
    Réponses: 4
    Dernier message: 07/02/2009, 19h56

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo