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

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

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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?