PDA

View Full Version : سوال: نمایش یک input خاص مثل textbox بعد کلیک کردن بر روی یه checkbox



Sh_Asgharian
جمعه 03 مهر 1388, 16:10 عصر
سلام
من می خوام یه checkbox روی صفحه html قراربدم که با کلیک کردن کاربر بر روی آن textbox خاصی برای دریافت داده از کاربر نمایش داده شود و اگر کاربر دوباره بر روی checkbox کلیک کند textbox مربوطه hidden ویا readonly شود.لطفا منو راهنمایی کنید.

afi_program
شنبه 04 مهر 1388, 12:47 عصر
از ajaxیا php استفاده کن و متد oncheck استفاده کن .
موفق باشی

Sh_Asgharian
شنبه 04 مهر 1388, 20:59 عصر
از ajaxیا php استفاده کن و متد oncheck استفاده کن .
موفق باشی
خیلی ممنون
من با jsp کار می کنم و کد html را اینجا گذاشتم ولی کار نمی کنه.از javaScript استفاده کردم:


<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1252">
<script type="text/javascript">function newfunc(){
if(document.form1.elements['resident'].value.equals('yes')){
document.form1.elements['averagewithtract'].disabled=false;
}
else {
document.form1.elements['averagewithtract'].value='';

document.form1.elements['averagewithtract'].disabled=true;
}
}
</script>
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("utf8"); %>

<form name="form1" action="farsisazi.jsp">
<INPUT id=averagewithtract size=10
name=averagewithtract ><INPUT id=resident type="checkbox" value=yes
name=resident onclick="newfunc()">

</form>
</body>
</html>

afi_program
یک شنبه 05 مهر 1388, 18:46 عصر
این درست شده ی کد:

<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type"
content="text/html; charset=windows-1252">
<script type="text/javascript">function newfunc(){

if(!document.form1.elements['resident'].checked){

document.form1.elements['averagewithtract'].style.visibility="hidden";
}
else {

document.form1.elements['averagewithtract'].value='';

document.form1.elements['averagewithtract'].style.visibility="visible";;
}
}
</script>
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("utf8"); %>

<form name="form1" action="farsisazi.jsp">
<INPUT id="averagewithtract" style="visibility:hidden;" name="averagewithtract" >
<INPUT id="resident" type="checkbox" name="resident" vlue="yes" onclick="newfunc()">

</form>
</body>
</html>
موفق باشی