MyNameIsSean Posted June 20, 2017 Report Share Posted June 20, 2017 Hi, I have a relational database set up in a way that I have a Customers table, Products table, and I create entries in the Proposal table, that links the 2 tables together. I would not like to create a proposal that connects the same customer to the same product twice, however there is one product that is open (id = 16), and is the exception (i can have multiple proposals created for the same customer, to that open product). I was thinking that I can create a checking field in the Proposal table that is a unique text field, and it will take a concatenate value of the customer Id and the product id to create a unique identifier. However it will not work for the open product, so I was thinking to insert a random number into the checking field such that it will bypass the unique value criteria present in that field. I currently have this, which the concatenate function works perfectly in generating and inserting the checking value, but the random value inserts "undefined" into the field. <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var identifier1 = document.getElementById("InsertRecordProduct_ID").value; var identifier2 = document.getElementById("InsertRecordCustomer_ID").value; var concat_identifier = identifier1 + "P" + identifier2 + "C"; if (identifier1 !== "16") { document.getElementById("InsertRecordChecker").value = concat_identifier; } else { document.getElementById("InsertRecordChecker").value = Math.random().ToString().value; } } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> Is there a problem with my code, or is there a better solution to this problem? Thanks in advance. Quote Link to comment Share on other sites More sharing options...
MyNameIsSean Posted June 23, 2017 Author Report Share Posted June 23, 2017 I have come up with the following solution: <SCRIPT LANGUAGE="JavaScript"> function concatenate() { var identifier1 = document.getElementById("InsertRecordProduct_ID").value;var identifier2 = document.getElementById("InsertRecordCustomer _ID").value; var concat_identifier = identifier1 + "P" + identifier2 + "C"; var text = ""; var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; for( var i=0; i < 5; i++ ) text += possible.charAt(Math.floor(Math.random() * possible.length)); if (identifier1 !== "16") { document.getElementById("EditRecordChecker ").value = concat_identifier ; } else { document.getElementById("EditRecordChecker ").value = text; } } document.getElementById("caspioform").onsubmit=concatenate; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.