Nmarediya Nmarediya - 23 days ago 5
HTML Question

how can I print javascript variable in input type textbox value like php echo

It is possible like php in javascript as below....

<?php
$var1 = "Hello";
$var2 = "World";
?>
<input type="text" value="<?php echo $var1; ?>" />
<input type="text" value="<?php echo $var2; ?>" />


<script type="text/javascript">
var str = "abc,def,ghi,jkl,mno,pqr";
var x = str.split(",");
</script>


I have input
type='text'
in the body tag like

<input id="txtOne" name="txtOne" type="text" value="I want to print here using javascript x[0]" />

<input id="txtOne" name="txtOne" type="text" value="I want to print here using javascript x[1]" />


Thanks.

Answer
Create Cookies in page 1 (Create Cookies On this page )
    <script type="text/javascript">
         function createCookie(name,value,days) {
              if (days) {
                var date = new Date();
                date.setTime(date.getTime()+(days*24*60*60*1000));
                var expires = "; expires="+date.toGMTString();
          }
          else var expires = "";
               document.cookie = name+"="+value+expires+"; path=/";
          }
   var PartyDetail = $("#firstname").val() +"|"+$("#middlename").val()+"|"+$("#lastname").val();

  createCookie('cookiesPartyDetail',PartyDetail,2);
    </script>

  Now read cookies on second page

 <script type="text/javascript">
      function readCookie(name) {
          var nameEQ = name + "=";
          var ca = document.cookie.split(';');
          for(var i=0;i < ca.length;i++) {
               var c = ca[i];
               while (c.charAt(0)==' ') c = c.substring(1,c.length);
               if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
             }
            return null;
       }
     window.onload = function()
      {
          var str = readCookie('cookiesPartyDetail');
          //var str = "firstname,middlename,lastname";
          var x = str.split("|");
          for (i = 0; i < 3; i++) 
          { 
            $(".pending_order_"+[i]).val(x[i]);
          }

      } 

  function delete_cookie(name) {
    document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
     }
 </script>

 <input class="pending_order_0" id="firstname" name="firstname" type="text"  /> 
 <input class="pending_order_1" id="middlename" name="middlename" type="text" />
 <input class="pending_order_2" id="lastname" name="lastname" type="text" />

 if I want to use again in input type hidden field same like firstname, middlename, lastname my code is here..

 <input class="pending_order_0" id="firstname" name="firstname" type="hidden"  /> 
 <input class="pending_order_1" id="middlename" name="middlename" type="hidden" />
 <input class="pending_order_2" id="lastname" name="lastname" type="hidden" />