How to add options to the drop down using javascript

<!DOCTYPE html>
<html>
<head>
	<script>
		function myFunction()
		{   var nums = {4:"four",5:"five"};
		    for(var key in nums)
	     	{
				var x = document.getElementById("category");
	     		var option = document.createElement("option");
	     		option.text = nums[key];
		 		option.value = key;
	     		x.add(option);
			}
		}		
	</script>
</head>
<body>
	<select id="category">
	      <option value="1">one</option>
		  <option value="2">two</option>
		  <option value="3">three</option>
	  </select>
	<button onclick = "myFunction()">Click here to add</button>
	
</body>
</html>

How to insert unique values in an array in Javascript

<!DOCTYPE html>
<html>
<head>
	<script>
		function myFunction()
		{
			var array1 = [551,445,665,551,778,443,665,334,445];
			var array2 =[];
			console.log("array1length "+array1.length+"\n");
			var display1 ="array1length "+array1.length+"\n";
			for(var i=0;i<array1.length;i++)
				{   
					display1 +=array1[i]+"\n";
					if(array2.indexOf(array1[i])<0)
					{
						array2.push(array1[i]);
					}
				}
			console.log("array2length "+array2.length+"\n");
			var display2 ="array2length "+array2.length+"\n";
			for(var j=0;j<array2.length;j++)
				{   
					display2 +=array2[j]+"\n";
			    }
				document.getElementById("array1display").innerHTML = display1;
				document.getElementById("array2display").innerHTML = display2;	
			}		
	</script>
</head>
<body>
	<p id="array1display"></p>
	<p id="array2display"></p>
	<button onclick = "myFunction()">Click here to see arrays</button>
	
</body>
</html>

Transaction type internal ids to use in the Suite script search filters

Typeinternal id
Assembly BuildBuild
Assembly UnbuildUnbuild
BillVendBill
Bill CCardVendCard
Bill CreditVendCred
Bin Putaway WorksheetBinWksht
Bin TransferBinTrnfr
Bill PaymentVendPymt
Cash RefundCashRfnd
Cash SaleCashSale
CheckCheck
CommissionCommissn
Credit CardCardChrg
Credit MemoCustCred
Currency RevaluationFxReval
Customer DepositCustDep
Customer RefundCustRfnd
DepositDeposit
Deposit ApplicationDepAppl
Expense ReportExpRept
Inventory AdjustmentInvAdjst
Inventory CountInvCount
Inventory DistributionInvDistr
Inventory TransferInvTrnfr
Inventory WorksheetInvWksht
InvoiceCustInvc
Item FulfillmentItemShip
Item ReceiptItemRcpt
JournalJournal
OpportunityOpprtnty
PaymentCustPymt
Purchase OrderPurchOrd
QuoteEstimate
Return AuthorizationRtnAuth
Sales OrderSalesOrd
Sales Tax PaymentTaxPymt
Statement ChargeCustChrg
TransferTransfer
Transfer OrderTrnfrOrd
Vendor Return AuthorizationVendAuth
Work OrderWorkOrd

Reference:

http://blog.prolecto.com/2014/01/03/netsuite-searchfilter-internal-transaction-type-codes/

Suitescript 2.0 Client script example

/**
  *@NApiVersion 2.0
  *@NScriptType ClientScript
  */
 define(['N/ui/dialog','N/search'],
     function(dialog,search) {
      function pageInitfun(Scriptcontext) 
      {
          var cRecord = Scriptcontext.currentRecord;
          var mode = Scriptcontext.mode;
           var options = {
             title: 'Hello!',
             message: 'pageInit Triggered!'
          };
         try {
            dialog.alert(options);
           log.debug ({
              title: 'Success',
              details: 'cRecord: '+cRecord+' mode: '+mode
           });
          } 
         catch (e) {
           log.error ({
            title: e.name,
            details: e.message
          });
         }
      }
     function fieldChangedfun(Scriptcontext) {
       var cRecord = Scriptcontext.currentRecord;
       var sublistId = Scriptcontext.sublistId;
       var fieldId = Scriptcontext.fieldId;
       var linenum = Scriptcontext.line;
       var columnid = Scriptcontext.column;
       var options = {
         title: 'Hello!',
         message: 'validateInsert Triggered!'
        };
        try {
         dialog.alert(options);
         log.debug ({
          title: 'Success',
          details: 'cRecord: '+cRecord+' sublistid: '+sublistId+' fieldId: '+fieldId+' linenum: '+linenum+' columnid: '+columnid
         });
         return true;
        } 
        catch (e) {
         log.error ({
           title: e.name,
           details: e.message
        });
       }
     }
    function lineInitfun(Scriptcontext) {
      var cRecord = Scriptcontext.currentRecord;
      var sublistid = Scriptcontext.sublistId;
      var options = {
        title: 'Hello!',
        message: 'lineInit Triggered!'
     };
     try {
       dialog.alert(options);
      log.debug ({
         title: 'Success',
         details: 'cRecord: '+cRecord+' sublistid: '+sublistId
      });
      return;
     } 
     catch (e) {
      log.error ({
       title: e.name,
       details: e.message
     });
    }
  }
 function postSourcingfun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var sublistId = Scriptcontext.sublistId;
  var fieldId = Scriptcontext.fieldId;
  var options = {
    title: 'Hello!',
    message: 'postSourcing Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord+' sublistid: '+sublistId+' fieldId: '+fieldId
     });
     return;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
 function saveRecordfun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var options = {
    title: 'Hello!',
    message: 'saveRecord Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord
     });
     return true;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
 function sublistChangedfun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var sublistId = Scriptcontext.sublistId;
  var options = {
    title: 'Hello!',
    message: 'sublistChanged Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord+' sublistid: '+sublistId
     });
     return true;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
 function validateDeletefun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var sublistId = Scriptcontext.sublistId;
  var options = {
    title: 'Hello!',
    message: 'validateDelete Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord+' sublistid: '+sublistId
     });
     return true;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
 function validateFieldfun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var sublistId = Scriptcontext.sublistId;
  var fieldId = Scriptcontext.fieldId;
  var linenum = Scriptcontext.line;
  var columnid = Scriptcontext.column;
  var options = {
    title: 'Hello!',
    message: 'validateField Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord+' sublistid: '+sublistId+' fieldId: '+fieldId+' linenum: '+linenum+' columnid: '+columnid
     });
     return true;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
 function validateInsertfun(Scriptcontext) {
  var cRecord = Scriptcontext.currentRecord;
  var sublistId = Scriptcontext.sublistId;
  var options = {
    title: 'Hello!',
    message: 'validateInsert Triggered!'
    };
    try {
     dialog.alert(options);
     log.debug ({
      title: 'Success',
      details: 'cRecord: '+cRecord+' sublistid: '+sublistId
     });
     return true;
    } 
    catch (e) {
     log.error ({
       title: e.name,
         details: e.message
    });
   }
 }
  return {
      pageInit: pageInitfun,
     fieldChanged: fieldChangedfun, 
     lineInit: lineInitfun,
     postSourcing: postSourcingfun,
     saveRecord: saveRecordfun,
     sublistChanged: sublistChangedfun,
     validateDelete: validateDeletefun,  
     validateField: validateFieldfun,
     validateInsert: validateInsertfun     
  };
 });

How to pass information between HTML and PHP pages using jQuery AJAX

HTML page content

<!doctype html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<form id="sampleform" method="post">
    <div>
        Firstname:
        <input type="text" name="firstname" id="firstname" />
        Email:
        <input type="text" name="email" id="email" />    
        <input type="submit" name="subBtn" id="subBtn" value="Clickhere" />
    </div>
	<div id="results"></div>
</form>
<script type="text/javascript">
$(document).ready(function() {
    $('#sampleform').submit(function(e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            url: 'phppage.php',
            data: $(this).serialize(),
            success: function(resp)
            {
                var jsonData = JSON.parse(resp);
 
                // user is logged in successfully in the back-end
                // let's redirect
                if (jsonData.success == "1")
                {
					$('#results').append("Firstname "+jsonData.firstname + "<br>");
					$('#results').append("Email "+jsonData.emailid);
                    
                }
                else
                {
                    $('#results').append(jsonData.message");
                }
           }
       });
     });
});
</script>
</body>
</html>

PHP Page

<?php
if (isset($_POST['firstname']) && $_POST['firstname'] && isset($_POST['email']) && $_POST['email']) {
    echo json_encode(array('success' => 1,
	"emailid" =>$_POST['email'],
	"firstname" =>$_POST['firstname']));
} else {
    echo json_encode(array("failure"=>0,
	'message' => ="there is something wrong with the data"));
}
?>

How to print HTML form data using php

HTML code

<html>
<head></head>
<bosy>
<form action = "<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method = "POST">
<input type = "text" name = "first_name" id = "first_name">
<input type = "text" name = "last_name" id = "last_name">
<input type = "text" name = "emailed" id = "emailed">
</form>
</body>
</html>

PHP Code

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  echo "First Name ". $_POST['first_name'];
  echo "Last Name ". $_POST['last_name'];
  echo "Email ". $_POST['emailid'];  
}
?>

Difference between Javascript and jQuery Selectors

Finding HTML elements using ID, Classname, Tag, CSS Selectors

Javascript

var val = document.getElementById("id1"); //using id
var val = document.getElementsByClassName("cls"); //using classname
var val = document.getElementsByTagName("p"); //using tag name
var val = document.querySelectorAll("p.cls"); //using selector

jQuery

var val =$("#id1"); //using id
var val = $(".cls"); //using classname
var val = $("p"); //using tag name
var val = $("p.cls"); //using selector
Design a site like this with WordPress.com
Get started