Click to See Complete Forum and Search --> : alert problem
zuzupus
07-16-2003, 08:50 AM
hi,
i got problem rgarding alert i created a select time field
<td nowrap align="center">
<select name="time" >
<option value="8:0">8:0</option>
<option value="9:0">9:0</option>
<option value="10:0">10:0</option>
<option value="11:0">11:0</option>
</select>
<input type="button" name="systime" size="1" value=">" onclick="insertTime();">// when clciking on this button it wil show system time
</td>
<td nowrap align="center">
<input type="button" value="Save " name="Save" border="1" onclick="go();">
</td>
when i clicks on save button it show alert that atleast slect time
the function
function go(){
var myindex=document.forms["tstest"].bis.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
return false;
document.forms["test"].bis.focus();
}
document.test.submit();
}//submit go()
but the problem is when i clcik on this button it show the system time and i jsut want to avoid this alert,i mean i dont want this alert when button 'systime' is clicked so how to avoid this complexity on the other hand i also dont want user to clcik save button without selecting time
thanks in advance
Phil Karras
07-16-2003, 12:19 PM
First you need to show us how you implemented: selectedIndex
You may need to use: ...selectedIndex.value for the check, but I won't know till you show us the implementation of selectedIndex.
zuzupus
07-17-2003, 03:04 AM
thanks alot well im pasting code below
<form name=tstest>
<td nowrap align="center">
<select name="von">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
<td nowrap align="center">
<select name="bis" >
<option value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
<input type="button" name="now" size="1" value=">" onclick="insertTime();">//acts like clock
</td>
<td nowrap align="center">
<input type="button" value="S" name="Save" border="1" onclick="go();">
</td>
</form>
<script language="JavaScript">
function go(){
var myindex=document.forms["tstest"].bis.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time from bis drop-down menu is selected.");
}
else {
document.tstest.submit(); }
}//submit go()
var times = new Array ();
function createArray() {
for (i=0; i<document.tstest.bis.length; i++) {
times[times.length] = new Option(document.tstest.bis[i].value, document.tstest.bis[i].value);
}
}
function insertTime() {
time = new Date();
hour = time.getHours();
minute = time.getMinutes();
hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
minute = minute.toString().length < 2 ? "0"+minute : minute;
while (document.tstest.bis.length > 0) {
document.tstest.bis.options[document.tstest.bis.length-1] = null;
}
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.tstest.bis.options[document.tstest.bis.length] = anOption
for (i=0; i<times.length; i++) {
document.tstest.bis.options[document.tstest.bis.length] = times[i];
}
document.tstest.bis.options.selectedIndex = 0;
}
</script>
the problem above is when i click 'now' button it will get system and afterward when i click on save it will submit the form i dont no why its always show alert
thansk in advance
zuzupus
07-17-2003, 05:33 AM
Phil got any solution for this alert problem as i am not able to rectify the problem :)
thanks
Phil Karras
07-17-2003, 07:32 AM
You'll need to give a bit more. I'm assuming that things like:
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
mean that a server-side script is filling in values here, well, I don't have the server-side script
doing it for me so I get nothing in the bis pull-down.
It's up to you to supply everything I need to help. So, fill in some valid values for me so I
can see the problem.
zuzupus
07-17-2003, 07:36 AM
function fillDD($min, $max, $selected)
{
for($i=$min; $i<24; $i++) {
for($j=$max; $j<60; $j+=5) {
if($i == $selected && $j == $selected) {
print("<option SELECTED value='$i:$j'>$i:$j</option>\n");
}
else {
print("<option value='$i:$j'>$i:$j</option>\n");
}
}//for($j)
} //for($i)
}
<td>
<select name="von">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
hope this is clear
thanks
Phil Karras
07-17-2003, 01:35 PM
Lety me see, I asked you to replace these kinds of lines:
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
with html code and you're asking me if this:
<td>
<select name="von">
<option selected value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>
</select>
</td>
is clear? Sure looks the same to me. So, until you can give the
HTML code generated by the server-side code, don't bother listing
any more code.
Also, until you can post the generated HTML I won't be able to
help further.
zuzupus
07-18-2003, 04:25 AM
<body onload="createArray()">
<form name=tstest>
<td>
<select name="von" size="1">
<option value="08:00">08:00</option>
<option value="09:00">09:00</option>
<option value="10:40">10:40</option>
</select>
</td>
<td>
<select name="bis" size="1" onChange="calculateDiff()">
<option value="08:00">08:00</option>
<option value="09:00">09:00</option>
<option value="12:10">12:10</option>
</select>
<input type="button" name="now" value="Insert" onclick="insertTime();calculateDiff()">
</td>
<td>
<input size="2" type="text" value="0" name="ist" readonly></td>
<input type="button" value="S" name="Save" border="1" onclick="go();">
</form>
<script type="text/javascript">
function go(){
var myindex=document.forms["tstest"].bis.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time from bis drop-down menu is selected.");
}
else {
document.tstest.submit(); }
}//submit go()
function calculateDiff() {
var time =document.forms["tstest"].elements["von"].value.split(":");
totime=parseInt(time[0]*60)+parseInt(time[1]);
var time1 =document.forms["tstest"].elements["bis"].value.split(":");
time2=parseInt(time1[0]*60) +parseInt(time1[1])
diff=(time2-totime)
min=(diff%60)
hrs=(diff-min)/60
if (hrs<=9)
hrs="0"+hrs
if(min<=9)
min="0"+min
document.forms["tstest"].elements["ist"].value =hrs+":"+min;
}
var times = new Array ();
function createArray() {
for (i=0; i<document.tstest.bis.length; i++) {
times[times.length] = new Option(document.tstest.bis[i].value, document.tstest.bis[i].value);
}
}
function insertTime() {
time = new Date();
hour = time.getHours();
minute = time.getMinutes();
hour = time.getHours().toString().length < 2 ? "0"+hour : hour;
// remove all options
while (document.tstest.bis.length > 0) {
document.tstest.bis.options[document.tstest.bis.length-1] = null;
}
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.tstest.bis.options[document.tstest.bis.length] = anOption
// add orignal options
for (i=0; i<times.length; i++) {
document.tstest.bis.options[document.tstest.bis.length] = times[i];
}
document.tstest.bis.options.selectedIndex = 0;
}
</script>
still alert problem but when i use
for (i=0; i<times.length; i++) {
anOption = times;
}
then alert problem is solved but lots all my elements(08:00,09:00,12:10) from bis field only i can have system time
hope this will be more clear
thanks
Phil Karras
07-18-2003, 10:18 AM
I believe all you need to do it make another flag to set the
fact that you have clicked & used: insertTime()
Then check for that in your go() function where you check for
if (myindex==0 - now, at the end of the go function you need
to reset the new flag to false (or 0) so it can be checked again
if needed.