dongying7667 2014-03-19 19:01
浏览 191
已采纳

选中的单选按钮显示文本框

I've searched a couple of questions on this site but couldn't find a helpfull one, the problem which I have is:

I have 2 radio form boxes, which are called 'Youtube' and 'Picture',I want this: When I click on the radio box of Youtube a text form shows up, I can't fix this and thats why I hope you do guys! thank you for you time!

my Javascript:

        <SCRIPT LANGUAGE="JavaScript">
    $("input[type='radio']").change(function(){

   if($(this).val()=="youtube")
   if($(this).val()=="pic")
   {
      $("#youtube").show();
   }
   else
   {
       $("#youtube").hide(); 
   }

    });
    </script>

My form:

 echo '
   <form action="post.php" method="post">
    title: <input name="title" type="text" id="title"><br />';

    //Picture link: <input name="pic" type="text" SIZE="80" id="pic"><br />
    //Youtube link: <input name="youtube" type="text" SIZE="80" id="youtube"><br />';
    echo '
    <input type="radio" name="youtube" value="youtube">Youtube <input style="display: none;" type="text" name="youtube" id="youtube"/> | <input type="radio" name="pic" value="pic">Picture <input style="display: none;" type="text" name="pic" id="pic"/><br />
    Category game: 
     <select name="cat">';
      while($row=mysql_fetch_array($query2)){
echo '
       <option value="'.$row["nameID"].'">'.$row["name"].'</option> // here is the problem
        '; }
      echo '
     </select>
    <input type="submit" name="submit" value="submit">
   </form>
 ';
  • 写回答

4条回答 默认 最新

  • doushan1863 2014-03-19 19:29
    关注

    I think you need do this..

            $("input[type='radio']").change(function(){
    
        if($(this).val()=="youtube")
        {
           $("#youtube").show();
           $("#pic").hide();
        }
         if($(this).val()=="pic")
        {
           $("#pic").show();
           $("#youtube").hide();
        }
    
    });
    

    this will work fine, but you must be carefully >>look at this mate:

    <input type="radio" name="youtube" value="youtube">Youtube <input style="display: none;" type="text" name="youtube" id="youtube"/> 
    


    Picture

    when you set a radio name, set the name of radio same..like youtube, youtube ... also, look at a nother name in form, you use a same name for multiple elements, and this wrong mate, give another element defferant name .. to can get it on php side, without any error ...

    good luck

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决