Tuesday 15 April 2014

javascript - Adding js variable to html input tag -



javascript - Adding js variable to html input tag -

trying set paypal button recurring donations end @ specific date (dec 2017). want subscription length dynamic (someone signs in 2 months not have many recurrences signs bc less time until dec 2017). i'm new programming think i've set js code determine remaining months. question how input variable (numberofmonths) html input tag. need somehow place variable in value input name srt in line:

<input type="hidden" name="srt" value="myvariable">

right total code is:

<script> var date1=new date(); // blank uses current date var date2=new date(2017,11,31); //months 0 based in js dec var year1=date1.getfullyear(); var year2=date2.getfullyear(); var month1=date1.getmonth(); var month2=date2.getmonth(); if(month1===0){ //have take business relationship month1++; month2++; } var numberofmonths; numberofmonths=(year2-year1)*12+(month2-(month1-1)); homecoming numberofmonths; </script> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick-subscriptions"> <!--you need set email paypal email or secure merchant id --> <input type="hidden" name="business" value="tez9lzk9b36x8"> <input type="hidden" name="lc" value="us"> <input type="hidden" name="item_name" value="monthly donation"> <input type="hidden" name="item_number" value="1234"> <input type="hidden" name="no_note" value="1"> <input type="hidden" name="no_shipping" value="2"> <input type="hidden" name="src" value="1"> <input type="hidden" name="p3" value="1"> <input type="hidden" name="currency_code" value="usd"> <input type="hidden" name="bn" value="pp-subscriptionsbf:btn_subscribecc_lg.gif:nonhosted"> <input type="hidden" name="srt" value="35"> <input type="hidden" name="t3" value="m"> <table> <tr><td>enter donation amount</td></tr> <tr><td>$ <input type="text" name="a3" maxlength="60"></td></tr> </table> <input type="image" src="https://www.paypal.com/en_us/i/btn/btn_donatecc_lg.gif" border="0" name="submit" alt="paypal - safer, easier way pay online!"> <img alt="" border="0" src="https://www.paypal.com/en_us/i/scr/pixel.gif" width="1" height="1"> </form>

you should add together id attribute:

<input type="hidden" name="srt" value="myvariable" id="numberofmonths" />

and then:

<script> document.getelementbyid("numberofmonths").value = (function(){ var date1 = new date(), month1 = date1.getmonth(), year1 = date1.getfullyear(), date2 = new date(2017,11,31), month2 = date2.getmonth(), year2 = date2.getfullyear(); if(month1===0){ month1++; month2++; } homecoming (year2-year1)*12+(month2-(month1-1)); }()); </script>

javascript html paypal

No comments:

Post a Comment