Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15

Thread: alert problem

  1. #1
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts

    alert problem

    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

  • #2
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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 ....
    Code:
    if (myindex==-1) {
    Dale Ellis
    __________________

  • #3
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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

  • #4
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I meant your code should be more like this:
    Code:
    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
    Dale Ellis
    __________________

  • #5
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I think it will be easyier to understand with all the code up.
    Dale Ellis
    __________________

  • #7
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #8
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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
    Dale Ellis
    __________________

  • #9
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Still a bit unsure of your problem, is this what you are after. I have made it so you have to pick a time.
    Code:
    <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>
    Dale Ellis
    __________________

  • #11
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #12
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #13
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hharchester got any solution for this

  • #14
    Regular Coder ellisd5's Avatar
    Join Date
    Jun 2002
    Location
    Uk
    Posts
    160
    Thanks
    5
    Thanked 0 Times in 0 Posts
    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.
    Dale Ellis
    __________________

  • #15
    Regular Coder
    Join Date
    Jun 2003
    Posts
    183
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Attached Files Attached Files


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •