开发者

How to retain the value of a text box?

This is the content on my view page and i want to replace the value from "0" when the monthfunc() is called...the monthfunc() is given below the view content

<tr>
<td>
<input type="submit" name="monthplus" id="monthplus" onClick="return monthfunc('monthplus');"  value=">>>>>>">
<input type="hidden" name="monthnum" id="monthnum" value="1">
<input type="text" name="monthname" id="monthname" value="0"  value="<? echo $month;?>" >
<input type="submit" name="monthminus" id="monthminus" onClick="return monthfunc('monthminus');" value="<<<<<<">
</td>
</tr>

My script is

function monthfunc(mnth)
{
 if(mnth == 'monthplus')
 {
  var yn = document.getElementById('monthnum').value;
  ynpo = parseInt(yn)+1;
  if(ynpo==13)
  {
   ynpo=1;
  }

 }

 else if(mnth == 'monthminus')
 {
  var yn = document.getElementById('monthnum').value;
  ynpo = parseInt(yn)-1;
  if(ynpo==0)
  {
   ynpo=12;
  }
 }
  if(ynpo ==1)
  {
    document.getElementById('monthname').value = 'january';
    document.getElementById('monthnum').value = ynpo;
    retu开发者_运维技巧rn true;
  }
  else if(ynpo ==2)
  {
    document.getElementById('monthname').value = 'february';
    document.getElementById('monthnum').value = ynpo;
    return true;
  }
  else if(ynpo ==3)
  {
    document.getElementById('monthname').value = 'March';
    document.getElementById('monthnum').value = ynpo;
    return true;
  }
  return false;

}

How can i replace The value with the value like january february etc.. Actually i can change the values but cannot retain the values... i want to retain the values ,,,How to do that


For the monthname input you have two 'values'. What happens when you remove the first one?

Also, you really need to improve the structure of your function. For example, using the following array would reduce your code significantly:

var month=new Array(12);
month[0]="January";
month[1]="February";
month[2]="March";
month[3]="April";
month[4]="May";
month[5]="June";
month[6]="July";
month[7]="August";
month[8]="September";
month[9]="October";
month[10]="November";
month[11]="December";


I'm not sure I exactly understand your question, but by way of an answer:

One of the input elements in your HTML snippet has two value attributes:

value="0"

and

value="<? echo $month;?>"

I would start by removing one of them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜