can we do data validation in HTML using Javascript inside it

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 64
Joined: Thu Mar 14, 2013 6:10 am

Mon Apr 01, 2013 3:09 am

Can we do data validation in HTML

I am trying to create a combobox if the login is prod

<div style ="float:left; margin:0 15px 0 1px">

<select name="combo1" id="combo1" onchange="Monday()">
<option value="None">None</option>
<option value="test">test</option>

<select name="combo11" id="combo11" ">
<option value="None">None</option>
<option value="test">test</option>

<select name="combo12" id="combo12" ">
<option value="None">None</option>
<option value="test">test</option>

<div >


if($showdes_mgr =="Prod")
<select name="combo2" id="combo2" >
<option value="None">None</option>
<option value="test">test</option>




php-forum Fan User
php-forum Fan User
Posts: 973
Joined: Mon Oct 01, 2012 12:32 pm

Mon Apr 01, 2013 9:00 am

You don't want to do any kind of validation client side. That said, if you just want something hidden or shown based on user selections, jquery is the way to go. that's not validation though. often I'll have form elements hidden with css (display:none) and then use jquery to toggle() them etc. here's an example...

Code: Select all

    .inactivePhone {
echo '<fieldset>
<legend>Telephone Information</legend>';
echo '<span style="float:right;"><input type="checkbox" id="activeOnly" name="activeOnly" checked />Active numbers only<br style="clear:both;" /></span>';
$phoneList = Phone::getNumbers(PHONE_TYPE_USER, PHONE_DESCR_ALL, $activeUser->id);
if (!$phoneList or $phoneList->rowCount()==0){
    'No numbers listed';
} else {
    while ($row = $phoneList->fetch(PDO::FETCH_ASSOC)){
        $tmp = new Phone($row);
        echo $tmp->displayFields();
echo '
        <div class="row" id="newNum" style="display:none;">      
            <label>New Phone</label>
            <input type="text" name="new_area" value="" size="3" maxlength="3" /> -
            <input type="text" name="new_prefix" value="" size="3" maxlength="3" /> -
            <input type="text" name="new_line" value="" size="4" maxlength="4" />' . 
            Phone::createPhoneDescrDropdown() . '</div>';
echo '<input type="button" id="showNew" value="Add Number" style="font-size:.7em;"/>';
echo '</fieldset>';
There are actually 2 examples there; inactive numbers are hidden by default by the first style, and then shown when 'active only' checkbox is clicked, or there's the inputs for adding a new number that are always there, but hidden until the user clicks add new.

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 8 guests