Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2011
    Location
    Mumbai
    Posts
    19
    Thanks
    10
    Thanked 0 Times in 0 Posts

    javasctipt two function call

    <script type="text/javascript">
    function CheckTextboxBlank(){
    if(document.getElementById("addntp").value==""){
    alert("Add NTP server");

    }
    }
    </script>

    <input type="text" value="" id="addntp" />
    <input type="button" value="Add" onclick="CheckTextboxBlank();" /><br />
    Here when i click on add on button on add ntp server then my function CheckTextboxBlank(); call nd i get a msg add ntp server and process is continue but i want to stop the process here when there is empty text box so plz help me ... i use this text in form <form id="datetimeform" name="datetimeform" method="post" action="datetimeconfig.php" style="margin:0;padding:0">
    and also i call another function too when there is some text in add ntp server

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    To prevent a form from submitting when the form data is invalid you need to return false to the fotrm's onsubmit event.
    Code:
    <form method="post" action = "" onsubmit="return validateFormData();" />
    Code:
    function validateFormData() {
         //if any form data is invalid
         //return false;
         //if all form data is valid
         //return true;
    }
    To validate the text box, you need to specify what characters are allowed and then you could use a regular expression to check for those characters.

    Also, the name attribute in <form> is deprecated and shouldn't be used.

  • Users who have thanked bullant for this post:

    harry343 (04-25-2011)

  • #3
    New Coder
    Join Date
    Apr 2011
    Location
    Mumbai
    Posts
    19
    Thanks
    10
    Thanked 0 Times in 0 Posts
    see i have an page like this
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

    <link href="styles/table.css" rel="stylesheet" type="text/css" media="screen">
    <link href="styles/config.css" rel="stylesheet" type="text/css" media="screen">

    <script src="scripts/commonfunction.js" type="text/javascript"></script>
    <script type="text/javascript">
    function CheckTextboxBlank(){
    if(document.getElementById("addntp").value==""){
    alert("Add NTP server");
    return;
    }
    }


    function Submit(buttonvalue)
    {
    document.getElementById('divLoginStatus').innerHTML = '<table cellpadding="5" cellspacing="0" style="font:Verdana, Geneva, sans-serif; font-size:12px; " ><tr><td><img src="images/rc-loader.gif"></td><td>Processing...</td></tr></table>';
    }


    function getTimeZone()
    {
    var x=document.getElementById("select_time_zone");
    x.value="<?php echo $timezone?>";
    }

    </script>
    </head>

    <body onload="getTimeZone();">
    <div class="mainBody" height="500px">
    <form id="datetimeform" name="datetimeform" method="post" action="datetimeconfig.php" style="margin:0;padding:0">


    <div class="TitleBar">System Time </div>
    <div style="padding-top:10px">
    &nbsp; &nbsp; &nbsp; &nbsp;Configure the System Time for Controller.
    </div>
    <div style="padding-top:10px; padding-left:30px" id="divLoginStatus">
    <?php
    require_once('/portal/scripts/error-status.php');
    echo geterror();
    ?>
    </div>
    <br><br>
    <div class="TitleBar"> Time Zone
    </div>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
    <td style="padding-left:30px; padding-top:10px" width="35%" >
    <select name="select_time_zone" id="select_time_zone" >
    <option value="GMT-12">(GMT -12:00) International Date Line West</option>
    <option value="GMT-11">(GMT -11:00) Midway Island , Samao</option>
    <option value="Fiji">(GMT +12:00) Fiji, Marshall Is.</option>
    </select>
    </td>
    </tr>
    </table>
    <br><br>
    <div class="TitleBar"><input name="set" type="radio" value="manually" checked="checked" />&nbsp;&nbsp;&nbsp;&nbsp;Manually Set Time</div>

    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr class="RowDivider">
    <td colspan="2" class="RowDivider"><img src="/images/slug.gif" width="10" height="1"></td>
    </tr>
    <tr>
    <td style="padding-left:30px; " width="35%" >Date : </td>
    <td >
    <input name="mm" type="text" id="mm" value="<?php
    echo $ini_val_mm;

    ?>" size="2" maxlength="2" />
    /
    <input name="dd" type="text" id="dd" value="<?php echo $ini_val_dd;?>" size="2" maxlength="2" />
    /
    <input name="yyyy" type="text" id="yyyy" value="<?php echo $ini_val_yy;?>" size="4" maxlength="4" />
    (mm / dd / yyyy)
    </td>
    </tr>
    <tr class="RowDivider">
    <td colspan="2" class="RowDivider"><img src="/images/slug.gif" width="10" height="1"></td>
    </tr>
    <tr>
    <td style="padding-left:30px; " width="35%" >Time : </td>
    <td >
    <input name="hr" type="text" id="hr" value="<?php echo $ini_val_hr;?>" size="2" maxlength="2" />
    :
    <input name="min" type="text" id="min" value="<?php echo $ini_val_min;?>" size="2" maxlength="2" />
    &nbsp;( hr : min )
    </td>
    </tr>
    </table>
    <br><br>
    <div class="TitleBar"><input name="set" type="radio" value="ntp" <?php

    if(empty($selntpserver))
    {
    $error_text="no ntp server selected.";
    AddLog("time.php","no ntp server selected.",ERR_DEBUG_HIGH);
    }
    else
    {
    $error_text="ntp server is selected.";
    AddLog("time.php","no ntp server selected.",ERR_DEBUG_HIGH);
    echo "checked=\"checked\"";
    }
    ?>>&nbsp;&nbsp;&nbsp;&nbsp;Automatically Set Time</div>
    <table cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr class="RowDivider">
    <td colspan="2" class="RowDivider"><img src="/images/slug.gif" width="10" height="1"></td>
    </tr>
    <tr>
    <td style="padding-left:30px; " width="35%" >Select NTP server : </td>
    <td style=" padding-bottom:1px">
    <select name="ntp_server" id="ntp_server">
    <?php


    for($i=0; $i<count($present_ntp); $i++)
    {
    $ntpserver = $present_ntp[$i] ;

    $error_text="ntpserver:".$ntpserver;
    AddLog("time.php","no ntp server selected.",ERR_DEBUG_HIGH);

    if(strcasecmp($ntpserver,$selntpserver)==0)
    {
    echo "<option value=".$ntpserver." selected >".$ntpserver."</option>";
    }
    else
    {
    echo "<option value=".$ntpserver." >".$ntpserver."</option>";
    }
    }
    ?>

    </select>
    <input name="button" type="submit" id="button" value="Remove" class="FormButton"/>
    </td>
    </tr>
    <tr class="RowDivider">
    <td colspan="2" class="RowDivider"><img src="/images/slug.gif" width="10" height="1"></td>
    </tr>
    <tr>
    <td style="padding-left:30px; " width="35%" >Add NTP server : </td>
    <td >
    <input name="addntp" type="text" id="addntp" value="" maxlength="30" />
    <input name="button" type="submit" id="button" value="Add" class="FormButton" onclick="CheckTextboxBlank();"/>
    </td>
    </tr>
    </table>

    <br><br>
    <div align="center">
    <input name="button" type="submit" value="Apply" class="FormButton" onclick="Submit(value);"/ >
    </div>
    </form>
    </div>


    </body>
    </html>

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    harry343 -

    See:- *** WARNING: Questions posted here will be deleted! ***.

    This forum is intended to be used only to post a completed (working) script for showcasing/benefit of others.

    Before you post again please read the forum rules and posting guidelines, and use code tags.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •