Tuesday, July 14, 2015

How to check or verify if atleast one of the form radio buttons were selected?

This page keeps collecting feedback from a user for 5 times and then responds with a thank you message. This example using jQuery + forms is mainly written to expand it to a series of questions to be posed to a user and collect feedback about them from the user in a compact way.


Include the jQuery reference:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script  type='text/javascript'>
        var count=1;

And then write the repeat function that does the trick to slide over a set of questions. Here only one question is repeating but you can extend it to other purposes.


        function submitform()
        {
                //alert(count);
                //alert("Inside submitform");
                if(count==5)
                {
                         $('#formid').html("Thank you!");
                }
                else
                {
                        //alert("Inside the submitform");
                        count=count+1;
                        $('#formid').html("<form action=\"submitform()\" method=\"post\" id=\"reportform\"> <label><input type=\"radio\" name=\"report\" value=\"customer\" /> Customers</label><br /><label><input type=\"radio\" name=\"report\" value=\"item\" /> Items Sold</label><br /><label><input type=\"radio\" name=\"report\" value=\"department\" /> Sales Departments</label><br /><label><input type=\"radio\" name=\"report\" value=\"person\" /> Sales People</label><br /><input type=\"button\" name=\"reportsubmit\" value=\"Submit\" onClick=\"verifyText(this.form)\" /> </form>");
                }
        }
</script>

</head>
<body>

Now the body section starts.. You can show the user whatever you want. Here I am asking the same question. Once you click the submit it verified is atleast one of the radio buttons is selected. If selected, then repeat if not, stay on the same page.

<div id="formid">
<form action="submitform()" method="post" id="reportform">
    <label><input type="radio" name="report" value="customer" /> Customers</label><br />
    <label><input type="radio" name="report" value="item" /> Items Sold</label><br />
    <label><input type="radio" name="report" value="department" /> Sales Departments</label><br />
    <label><input type="radio" name="report" value="person" /> Sales People</label><br />
    <input type="button" name="reportsubmit" value="Submit" onClick="verifyText(this.form)" />
</form>
</div>

This is the verify section:

<script>
function verifyText (form) {
        var checked = form.querySelector('input:checked');
        var value = checked ? checked.value : null;
        alert(value);
        if(value!=null)
                submitform();

}


</script>


Thursday, July 2, 2015

[Latex][MikTex][windows] Fixing the error that mathtools.sty package is not found

These are the steps I took on windows OS to fix the package error in MikTex.

Go to the console and type "cmd"

Now go to the directory where MikTex was installed on your machine.

>> cd C:\Program Files (x86)\MiKTeX 2.9

>> cd miktex\bin

And then with the administrator settings open the package console using this command:

>> mpm_mfc_admin

This prompts a gui where you can see different packages available. Simply search for the "mathtools" package and install it by clicking + symbol on the top-left side of this GUI. Hope this helps!


Tuesday, May 19, 2015

[Latex] Installing packages like mathtools, enumitem, etc on Windows 8 using MikTek 2.9

You can directly download a .sty file and refer it in your .tex file but not always this works as sometimes a single package may require other sub-packages to be installed.

Inorder to install a new package using MikTex on Windows 8, it is very simple. Here are the steps:

1. Search for cmd in the applications search option
2. And right click this option and choose 'Run as administrator'
3. Then go to the folder where MikTex 2.9 is installed. For me it is: 'C:\Program Files (x86)\MikTex 2.9'
4. Further go to the subdirectory: 'C:\Program Files (x86)\MiKTeX 2.9\miktex\bin'
5. Once you are in this folder, type the command mpm_mfc_admin on command prompt which pops out a MikTex Package Manager console showing the different packages available.
6. From here choose whatever package you want to install by selecting that and pressing the '+' option on the top.

Thats all folks! 

How to dump a .sql file into mysql database

There are different ways you can dump a .sql file into a mysql database. But here is a quick way to do this.

Assume that you want to load the file "datafile.sql" into database named "alldata" Simply use these commands:

>> mysql

>> use alldata;

>> source datafile.sql;

>> show tables; //Displays all the tables dumped into this database. 

Wednesday, April 8, 2015

Convert a byte array to Hexadecimal string in Java

Use the DatatypeConverter liibrary that can be imported as:

>> import javax.xml.bind.DatatypeConverter;

And then lets say certificate.getSignature() is returning a byte array, use these commands:

>> byte[] sign = certificate.getSignature();
>> String hexasign = DatatypeConverter.printHexBinary(sign);
>> System.out.println("Signature on the Certificate: "+hexasign+"\n");