SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Confirm Issue

  1. #1
    SitePoint Member
    Join Date
    Apr 2004
    Location
    13th Floor
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confirm Issue

    Hi all,

    I am trying to confirm if a the user leaves a field blank that is what they want to do. I am using the following code and the problem is no matter what I set the return to (ie, return true; return false; return if I click OK nothing happens, but if I click Cancel, the form is submitted.

    if (f.StartDate.value == ""){
    if (confirm("You have not selected a Start Date. All open incidents will be re-assigned.\n Click cancel if this is incorrect.")){
    return;
    }
    }

    Any ideas?

    TIA,
    Chris3125

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nearly impossible to tell what you're doing, as you've left out the most important part - the way in which the code is called. Try...
    Code:
    if (f.StartDate.value == "")
    return confirm("You have not selected a Start Date. All open incidents will be re-assigned.\n Click cancel if this is incorrect.");
    Otherwise, you'll need to show more.
    ::: certified wild guess :::

  3. #3
    SitePoint Member
    Join Date
    Apr 2004
    Location
    13th Floor
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the entire code block:
    Code:
    <script language="javascript">
    function doSubmit(){
    		var f = document.forms[0];
    if (f.StartDate.value == ""){
    if (confirm("You have not selected a Start Date. All open incidents will be re-assigned.\n Click cancel if this is incorrect.")){ 
    return;
    }
    }
    </script>
    It is being called by:
    Code:
    <input type="button" class="buttonStyle" name="Reassign" value="Re-Assign Incidents" onClick="doSubmit();">
    I know I can do a return confirm in the form tag, but I don't have access to the form tag. It is being called from another page.

    I tried what you suggested and it still didn't work.


    Quote Originally Posted by adios
    Nearly impossible to tell what you're doing, as you've left out the most important part - the way in which the code is called. Try...
    Code:
    if (f.StartDate.value == "")
    return confirm("You have not selected a Start Date. All open incidents will be re-assigned.\n Click cancel if this is incorrect.");
    Otherwise, you'll need to show more.

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hard to see how that would submit anything (a generic button doesn't submit, and you haven't called the Form.submit() method anywhere). I'll assume that's the only validation you're doing.
    Code:
    function chkStartDate(startdate)
    {
    	if (/^\s*$/.test(startdate.value)) //check for whitespace
    		return confirm("You have not entered a Start Date. All open incidents will be re-assigned.\n Click cancel if this is incorrect.");
    	else return true;
    }
    
    <input type="submit" class="buttonStyle" name="Reassign" value="Re-Assign Incidents" onClick="return chkStartDate(StartDate);">
    ::: certified wild guess :::


Bookmarks

Posting Permissions

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