Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

can we do data validation in HTML using Javascript inside it

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

can we do data validation in HTML using Javascript inside it

Postby stephenrodrics » 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>

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

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

<div >

<?php


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

}

?>

</div>
stephenrodrics
New php-forum User
New php-forum User
 
Posts: 57
Joined: Thu Mar 14, 2013 6:10 am

Re: can we do data validation in HTML using Javascript insid

Postby seandisanti » 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
<style>
    .
inactivePhone {
        
display:none;
    }
</
style>
<
script>
    $(
document).ready(function(){
        $(
"#showNew").click(function(){
            $(
"#newNum").toggle();
            $(
this).hide();
        });
        $(
"#activeOnly").click(function(){
            $(
".inactivePhone").toggle();
        })
    })
</script>
<?php
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_USERPHONE_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.
seandisanti
php-forum Fan User
php-forum Fan User
 
Posts: 838
Joined: Mon Oct 01, 2012 12:32 pm


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.