I am passing some values out of a form into a function so it is ready for database insertion.
The function theoretically works fine. However, it misses a unique value that puts me in trouble afterward.
I’m trying to generate a unique ID based on the data that is submitted to the database.
I want to generate the ID like this:
var mystringId = prodID+'{‘+selectId+’}’+selectedOptionValue;
Should output for example: 20{100}3{200}6.
In my sample it generates above the following:
20{100}3
20{200}6
because of the each();
$("#submitme").live('click', function() {
//var mystringId = prodID;
$('select').each(function() {
var addedOn = new Date();
var selectName= $(this).attr("name");
var selectId= $(this).attr("id");
var selectedOption = $(this).find('option:selected');
var selectedOptionValue = selectedOption.val();
var selectedOptionText = selectedOption.text();
var mystringId = prodID+'{'+selectId+'}'+selectedOptionValue;
db.transaction(function(tx) {
tx.executeSql('INSERT INTO xxxxx mystringId');
});
});
$.mobile.changePage( "#cart", { transition: "slideup"} );
});
From what I can gather from your question, you can simply do a each loop before your current code to generate the
mystringIdin the format your looking for to use inside your code.Code
Results
The results would be mystringId starting off with the value of prodID
mystringId = 20The first iteration of the loop would append
{100}3resulting inmystringId = 20{100}3The second iteration of the loop would append
{200}6resulting inmystringId = 20{100}3{100}6