Category Archives: Java Scripts

It contains Java Scripts that I learn newly.

How to submit a form to a new window in post method using javascript?

To submit a form to a new window in post method,

HTML

<form name="form_message_center_popup" id="form_message_center_popup" method="post" action="/folder/file.ext">
    <input type="text" name="user_name" id="user_name" value="abc"/>
    <input type="text" name="clientid" id="clientid" value="efg"/>
    <input type="button" onclick="form_submiter()" value="submit"/>
</form>

JavaScript

function customer_support_msg() {
    var customer_support = window.open("about:blank", "_form", "location=no, menubar=no, toolbar=no, fullscreen=yes, scrollbars=yes, resizable=yes, width=800, height=600, replace=true");
    document.forms["form_message_center_popup"].target='_form';
    document.forms["form_message_center_popup"].submit();
    return false;
}

Set custom validation message for HTML5 form required attribute.

Hi,
Set custom validation message for HTML5 form required attribute using the DOM function setCustomValidity . Please go through following example.

<input type="text" name="Username" id="Username" required="required" oninvalid="this.setCustomValidity('Username cannot be empty.')" />

Screenshot :

manukeerampanal

Regular Expression for Email Validation

The regular expression for email validation is follows :

^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$

The JS script for email validation can be written as follows :

function email_validator(mail_id) {
    var regexp=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})$/;
    if (regexp.test(mail_id)) {
        alert("This is a valid Email Id!!!");
        return true;
    }
    else {
        alert("This is an invalid Email Id!!!");
        return false;
    }
}

How to get selected text from drop down list (select box) using jQuery

It can be done as follows :

$("#dropdownid option:selected").text();

How to set a div fixed horizontally but not vertically?

To set the divs’ position horizontally fixed but not vertically, use the following code :

HTML

<div id="container">
    <div id="manu"></div>
</div>

CSS

<style type="text/css">
#container {
 position:relative;
    width:700px;
 height:1000px;
    top:50px;
    left:50px;
 background-color:yellow;

}

#manu{
    position:fixed;
    width:100px;
    height:100px;
    background-color:blue;
    margin-top:20px;
    margin-left:400px;
}
</style>

Jquery

<script type="text/javascript">
$(window).scroll(function(event) {
   $("#manu").css("margin-left", 400-$(document).scrollLeft());
});
</script>

To see demo please click the link below :

http://jsfiddle.net/kL33K/