...

View Full Version : alert problem



zuzupus
07-16-2003, 02:47 PM
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

ellisd5
07-16-2003, 03:00 PM
I dont really understand the question but 1 thing that might help you.

You should be checking if selectedIndex = -1 if you want to know if nothing is selected. so it should be ....


if (myindex==-1) {

zuzupus
07-16-2003, 03:21 PM
<I dont really understand the question but 1 thing that might <help you.
i just want that when i clcik on Save button without slecting time(the form must not submit) then above script is alright but at the same time i created a button called systime while clicking on this it will show system time after that when i clcik on save then form must submit
the idea behind select is user can select the system time but if he is lazy enough to select time then by mere clcik on systime button he will get time then there is no alert it can safely submit

<You should be checking if selectedIndex = -1 if you want to <know if nothing is selected. so it should be ....
[if (myindex==-1) {

function go(){
var myindex=document.forms["test"].time.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
return false;
document.forms["test"].time.focus();
}
if (myindex==-1){
document.test.submit();
}/

still it not works :(

hope u understood this

thanks

ellisd5
07-16-2003, 03:29 PM
I meant your code should be more like this:


function go(){
var myindex=document.forms["tstest"].bis.selectedIndex;
if (myindex==-1) {
alert("\nPlease be sure that time menu is selected.");
document.forms["test"].bis.focus();
} else {
document.test.submit();
}
}


Does that work :confused:

zuzupus
07-16-2003, 03:35 PM
no it also not working then other condition is failure as now when i wont select any time and clicks on save it submits form without showing any alert

i want some thing like this

when i wont select any time from time field---it will show alert
after selecting time it can submit form else
if i clicks on systime button to get systime straightway form must submit no need to alert

ellisd5
07-16-2003, 03:42 PM
I think it will be easyier to understand with all the code up.

zuzupus
07-16-2003, 03:47 PM
sorry i ddint understand what u mean by codes up as my heads keep on ringin :)
its really causing trouble if u coem with change code will really be appreciable

ellisd5
07-16-2003, 03:56 PM
Sorry,
I meant post all the code on this site (put it up).
There are bits of code such as bis that cant be seen.
Also seeing all the code will help me and others to understand the problem better

zuzupus
07-16-2003, 04:12 PM
ok sorry!----where ever u see bis take it as time
<form name=test>
<td nowrap align="center">
<select name="time">
<option value="<?=date('H:i')?>"><? echo (date('H:i')); ?></option>
<? fillDD(0, 0, -1); ?>//php function to get time
</select>
<input type="button" name="systime" size="1" value=">" onclick="insertTime();">
</td>
<td nowrap align="center">
<input type="button" value="Save" name="Save" border="1" onclick="go();">
</td>
</form>
//jscript

//submit
function go(){
var myindex=document.forms["test"].time.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
return false;
}
document.test.submit();
}//submit go()

//to get system time

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.test.time.length > 0) {
document.test.time.options[document.test.time.length-1] = null;
}
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.test.time.options[document.test.time.length] = anOption
for (i=0; i<times.length; i++) {
document.test.time.options[document.test.time.length] = times[i];
}
document.test.time.options.selectedIndex = 0;
}

//PHP function to get time from 0:0 till 23:55

function fillDD($min, $max, $selected)
{
for($i=$min; $i<24; $i++) {
for($j=$max; $j<60; $j+=5) {
$j = sprintf('%02d', $j);
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)
}

thansk in advance

ellisd5
07-16-2003, 04:31 PM
Still a bit unsure of your problem, is this what you are after. I have made it so you have to pick a time.


<html>
<head>

<script type="text/javascript">

var times = new Array ();
function createArray() {
for (i=1; i<document.test.time.length; i++) {
times[times.length] = new Option(document.test.time.options[i].value, document.test.time.options[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.test.time.length > 0) {
document.test.time.options[document.test.time.length-1] = null;
}
document.test.time.options[document.test.time.length] = new Option ("Select a time", "dummy")
var anOption = new Option(hour+":"+minute, hour+":"+minute);
document.test.time.options[document.test.time.length] = anOption
for (i=0; i<times.length; i++) {
document.test.time.options[document.test.time.length] = times[i];
}
document.test.time.options.selectedIndex = 1;
}

function go(){
var myindex=document.forms["test"].time.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
} else {
document.test.submit();
}
}//submit go()

</script>

</head>
<body onload="createArray()">

<form name=test>
<select name="time">
<option value="dummy">Select a time</option>
<option value="08:00">08:00</option>
<option value="09:00">09:00</option>
<option value="10:40">10:40</option>
</select>
<input type="button" name="systime" size="1" value=">" onclick="insertTime();">
<input type="button" value="Save" name="Save" border="1" onclick="go();">
</form>

</body>
</html>

zuzupus
07-17-2003, 08:27 AM
function go(){
var myindex=document.forms["test"].time.selectedIndex;
if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
} else {
document.test.submit();
}
}//submit go()

sorry but still its not working when i clcik on systime button to get system time and then try to submit the form still getting alert
i dont no what to do now

regards

zuzupus
07-17-2003, 09:23 AM
var objTimeSelect = document.getElementsByName('time');
alert(objTimeSelect)//return object
if (objTimeSelect != null){
var myindex = objTimeSelect.selectedIndex;
alert(myindex)// returns undefined
} else {
var myindex = 0
}

if (myindex==0) {
alert("\nPlease be sure that time menu is selected.");
}
else {
document.test.submit(); }
}//submit go()

when i modifed above script then the form submits no matter u selct time or not i mean to say now it works better when i click on systime but when i wont select any time and clicks on save still form submits,

looks very simple i dont no what i do as this situation

again i repeat the only idea behind butting this systime button which acts like clock to ensure that if user is lazy he can click this button and safely submit the time but if he go directly to click save then alert comes into picture

hopefully this time u know better solution for this

thanks

zuzupus
07-17-2003, 11:17 AM
hharchester got any solution for this :)

ellisd5
07-17-2003, 12:32 PM
I thought I had fixed it.
Can you view source of the page that is not working and email that code to me.

Me replicating your code is going wrong somewhere.

zuzupus
07-17-2003, 12:49 PM
hi,
txt file (attached one) which is mixture of php and javascript,hope it wont be painful for ur eyes just view at function go()
just visit this link

http://server2.vitodesign.com/scripts/diff.phtml

thanks alot



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum