dongxia2068 2014-04-29 06:34
浏览 103

如何使用if语句设置数组

So I have a program that is meant to output a message based on their form input on the previous page which I have grabbed with $_GET on the next page with php.

If believe it is something to do with setting the array with an if else statement.

Here is my php and JavaScript code :

<?php 
    session_start();
    $theirname = $_GET['theirname'];
    $yourname = $_GET['yourname'];
    $slct2 = $_GET['slct2'];
    $slct1 = $_GET['slct1'];
?>

<script type="text/javascript">
    var theirName = "<?php echo $theirname; ?>";
    var yourName = "<?php echo $yourname; ?>";
    var cardType = "<?php echo $slct1; ?>";
    var personType = "<?php echo $slct2; ?>";

    var myArray=[

"i need", 
"to make the contents of ",  
"this array",  
"conditional",  
"to the variable",  
"cardType",  
"and the variable",  
"personType", 


];

 //shuffle array:
myArray.sort(function(){return Math.round(Math.random());});

//print to screen
function printGreet()
{
document.getElementById('demo').innerHTML= [myArray.pop()];
}
</script>

And html:

    <button onclick="printGreet()" class="large-btn" id="generate-Btn" rows="20">Generate</button>
</div>
<div id="yourMes">
    <p>Your message:</p>
</div>
<textarea name="text1" class="large-fld" id="demo"> </textarea>

Demo of my site for more elaboration, here: http://ngrdev.com/jack/greatgreets2/index.php

  • 写回答

1条回答 默认 最新

  • dougu3988 2014-04-29 06:55
    关注

    Can you give what kind of value $_GET['slct2'] contain? As you are doing json_encode in php to $slct2 variable then you need to do json decode for cardType in javascript.

    Use json_encode in php, if your data is a array format or string with characters.

    For json decode check http://www.w3schools.com/json/json_eval.asp.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题