tags:

views:

67

answers:

2

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;
    return 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

+1  A: 

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.

Jonathan Nicol
+2  A: 

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";
zaf
Or just `var month = ["Jan", "Feb", "Mar", ...];`
Matt
where you are mentioning the change
udaya
+1 cheer for that.
zaf
@udaya Instead of having all those IF statements, you can use the array to do the same in a few lines. Please open another question if you don't understand.
zaf
@zaf I will check out
udaya
i replaced those if statements with the code but how can i change the month previously by clicking on the >>>>>> button i changed the month
udaya
@udaya Is your original question answered? If not then update your question with the new code. Otherwise open a new question because its not the same question as this.
zaf