My collection of things.

jKafer on the Net

Javascript Project: Interactive Quoting Tool

Task: Online quoting tool to be used to configure customized Widgets, assign a Smart Part Number to the configuration, display the full configuration and add up and display quoted price.

Javascript – check required fields in form – return to form

PROBLEM: check required fields (more than 2) before adding items to a database – this will help curb bad data entries in your database.

I have a form that uses .ajax to write to the database and then relist all the items added. Like a shopping cart…in a way.  So I split out the validation part – it was simpler this way.

<input type=”button” class=”addtocart_button” value=”Save” title=”Save” onClick=”ckItem()” />

SOLUTION:

When the “Save” button is clicked it runs: ckItem()  –

function ckItem(){
//javascript function loaded in header
   
   $formID = "itemEntry";
   //pulls information from form that was submitted
   $category = document.forms[$formID]['category'].value;
   $genius = document.forms[$formID]['desc1'].value;

   //checks required fields for data  
   if (!$category || !$genius) {
       //if required field(s) are blank, do not add record
      alert("Category & Description are required fields");
      if (!$category) {
         document.forms[$formID]['category'].focus();  //returns cursor to this field
         return;  //stops the function
      } else if (!$genius) {
         document.forms[$formID]['desc1'].focus();  //returns cursor to this field
      }
   } else {
      //if both fields have data, it will now write the data to the database
      saveItem();
   };
}

 

Web Hosting Options

My 3 favorite hosting options (in no specific order):

  • pair.com – I have hosted with pair.com for 15+ years and I have never had an outage or interruption of the service. They used to be more for the hands on web master that doesn’t need or want a graphical interface to do things. They have recently introduced a new Control Panel that will walk you through any and every thing you want to do. I highly recommend them.

  • justhost.com – I have hosted with justhost.com for the past 5 years or so. They offer unlimited hosting of domain names. They have a great control panel that offers you all the options you need or want. Lots of space for websites and email. I highly recommend them.

  • godaddy.com – I have worked with many sites that are using godaddy.com hosting services, some options they are are better than others. Recently they started offering WordPress as an option. The only “con” I have for them is that some of their web site building applications have a slow response when you are creating. But they do offer so many deals it’s hard to not like these guys.

Find the Index number of an item in a Javascript Array

I recently was creating a quoting form for a company that I was working for and I wanted to streamline as much as possible (i love to combine things or as I say, get more for my money!). When the quote was completed it would return a description of the items ordered and assign a Smart Part Number to the configuration.

  • So I have a list of categories – with options, setup as radio buttons.
  • When a selection is made I want to load that item (description, price, partNo) into the display area.
  • And build and display the Smart Part number.

TASK: The order in which the items are displayed and added to the display area is very important, so I coded the radio buttons with an ID – then I lookup that ID in an array and get the index number (order number) of that item and that is the placement in the smart part number.

Here is the javascript code I used to do that:

<SCRIPT language = "JavaScript">

//define array outside of a function to make it universally available
var arrPNC = [ "00", "A", "B", "C", "D", "E", "F", "G", "H"];
var itemOrder = 0;

//function to do the lookup and return index(order) must pass a letter
function findItem(tComp){
    findVal=tComp.value  //gets the value from the radio button
	//alert(findVal);  //if you want to see what is being searched for
    for(n=0;n<9;n++){
        //alert(arrPNC[n]); // if you want to see what is checked
        if(arrPNC[n]==findVal)
         {//if matches break from loop and get the index
            itemOrder = n;
        }
    }
     if (itemOrder > 0 ){       
       alert(findVal+ " is in position " + itemOrder + " in the array");
     } else {
       alert(findVal + " was not found in the array. Please try again.");
     }
     itemOrder = 0;
}
</script>

Example of the radio button input tag:
<input id="F" onclick="findItem(this);" type="radio" name="B" value="F" />F

Try it select an item below:

C   D   E   F   G   H   I


  • Count per Day

    • 23Visitors today:
    • 47Visitors per day:
    • 1Visitors currently online:
  • ScrapBook Software - MyMemoriesSuite
  • Latest Pins on Pinterest

    • These yoga poses can help you counteract your desk slouching.

    • Get this fast and easy tutorial for a baby quilt. It is made with beautiful batik fabrics. #quilting #batiks #diyproject #babyquilt ConnieKresin.com

    • grass green rocksteady quilt

    • A modern geometric quilt perfect for any nursery or home. Versatile enough to be used as a picnic or stroller blanket. It perfectly cosy and warm. Like all of our quilts, it has super soft minke backi More

    • blue ombre baby quilt - a fat quarter friendly pattern!

    • Лоскутная геометрия: Hunter's Star / Звезда охотника

    • kg17 -