Page 1 of 1

vali php options with javascript

Posted: Sat Oct 24, 2009 5:54 pm
by christalix
is there anyway to let a message popup if its empty selected option using javascript?

any help?


if(isset($add)) {
echo "<form name='form1' action='edit.php?&now=$now&nid=$nid' method='post'>\n";
echo "<div id='divEdit'>\n"
."<table width='100%'>\n"
."<tr>\n"
."<td width='10%'></td>\n"
."<td width='70%'>"._INPUT."</td>\n"
."<td width='10%'></td>\n"
."</tr>\n";
$query = "SELECT * FROM templates WHERE type != 'campaign' ORDER BY tid ASC";
$result5 = my_sql_query($query, "tid") or die ("Couldn't execute query because: ".mysql_error());
//echo $result5[0].'<br>';
//echo $result5[2]['num_rows'].'<br>';


echo "<tr>\n"
."<td width='0%'></td>\n"
."<td width='70%'><input name='contenttext' type='text' size='30' maxlength='50'>&nbsp;&nbsp;";
echo "&nbsp;&nbsp;<em>select</em>&nbsp;&nbsp;<select>";
echo "<option value=''></option";

foreach($result5[1] as $key => $value )
{
echo "<option value='1'>";
echo $value['description']."<br />";
echo "</option>";
}
echo "</select></td>";
echo "</tr>\n";
echo "<tr>\n"
."<td width='100%' colspan='3'></td>\n"
."</tr>\n"
."<tr>\n"
."<td width='10%'></td>\n"

."<td width='70%'><input type='submit' name='newCampaign' value='"._ADD."' id='button'>&nbsp;&nbsp;<input type='submit' name='reset' value='"._RESET."' id='button'></td>\n"
."<td width='10%'></td>\n"
."</tr>\n";
echo "</table>\n"
."</div>\n"
."</form>\n";

Re: vali php options with javascript

Posted: Sun Oct 25, 2009 8:17 am
by markusn00b
Something like this(?):

Code: Select all

 
<script type="text/javascript">
    function dosomething(theEl) {
        if(theEl.selectedIndex == 0) {
            alert("Please selected another option.");
            theEl.focus();
        }
    }
</script>
 
<select name="test" onchange="dosomething(this);">
    <option value="" selected="selected"></option>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
</select>
Your question is a little vague.

Mark.