www.webdeveloper.com
Results 1 to 9 of 9

Thread: class selectors

  1. #1
    Join Date
    Jun 2011
    Location
    California
    Posts
    383

    Lightbulb class selectors

    I'm using onbeforeload to make sure users don't navigate away from the page without saving. Although I want it to trigger the event only if they have clicked in and input box (tbox). Here's my code.


    Code:
    <script>
    $(document).ready(function(){
    	window.onbeforeunload = function(){
    		return "Your changes may not be saved.";
    	}
    
    	$("form").submit(function(){
    		
    		window.onbeforeunload = null;
    	});
    });
    
    </script>	
    
    
    <div class='module_header'>New Comment | <a class='f' href='<?php echo matry::here_to('lookup'); ?>'>Cancel</a></div>
    <form action='<?php echo matry::here(); ?>' method='post' onsubmit="var arr = new Array('NOTE1'); return mandatory(this, arr);">
    <table class='edit'>
    <tr><td>Note1 <?php tbox('NOTE1', 60, 4, 250); ?></td></tr>
    <tr><td>Note2 <?php tbox('NOTE2', 60, 4, 250); ?></td></tr><tr><td /></tr>
    <tr><td>Note3 <?php tbox('NDATA', 60, 6, 6000); ?></td></tr>
    <tr><td><?php echo lookup_link('Category', 'category', 'CATEGORY=Category&CATNAME=Description'); ?> <?php inp('CATEGORY',2); ?>
    	<input type='button' value='Clear' onClick="setval('CATEGORY',''); document.getElementById('CATNAME').innerHTML = '';">
    	<span id='CATNAME'></span></td></tr>
    <tr><td><?php echo button::save('Add Comment'); ?></td></tr>
    </table>
    </form>

    Any help would be greatly appreciated. Thanks in advance.

  2. #2
    Join Date
    Jun 2011
    Location
    California
    Posts
    383

  3. #3
    Join Date
    Sep 2008
    Location
    Dallas
    Posts
    154
    Just set a boolen variable to False. When they click on an input, set it to True. On unload, check to see if the variable is True. If so, run your code. If not, unload the doc.

  4. #4
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    You make it sound super easy.. could you elaborate more please.

  5. #5
    Join Date
    Sep 2008
    Location
    Dallas
    Posts
    154
    Well, I feel this is probably a school assignment, so I hate to code it for you. Just think about this: when your document loads, make a var called something like "editsMade". Set that to false. Create a function that will change editsMade to true. On your inputs, for the onclick events, call the function that will change your boolean variable to true. On your unload, check to see if editsMade is true or false. Do the appropriate action depending on that. This will suffice your need to see if the user clicked on an input. This will not check to see if the user actually made any changes, but it will warn them changes might have been made, which sounds like all you need.

  6. #6
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    thanks for the tips.. i'm working on it still.

  7. #7
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    it's confusing because i'm using these custom php tbox's (textboxs)..

    i'm struggling here.

  8. #8
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    This fixed my problem.


    Code:
    $(document).ready(function(){
    	
    
    $("input[type='text'], select, textarea").change(function()  < this line fixed me 
    
    
    {
    		window.onbeforeunload = function()
    			{
    			return "Your changes may not be saved.";
    			}
    	});
    	
    	
    	$("form").submit(function(){
    		
    		window.onbeforeunload = null;
    	});
    });

  9. #9
    Join Date
    Jun 2011
    Location
    California
    Posts
    383
    I'm still interested in figuring out the other way you suggested Javaboey..

    If i created a variable..

    var editsMade;

    function myFunction(editsMade)
    {
    this is where i'm confused as to what to write as the function.. would i say if the textbox is > 0 ??
    }

    help with that part please

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles