SitePoint Sponsor

User Tag List

Results 1 to 16 of 16

Thread: Morning Blues

  1. #1
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Morning Blues

    OK, having a bit of a mare this morning!

    Trying to validate 3 radio buttons so that an alert box is shown if the user tries to submit the form without checking any of the radios?

    Keep getting errors, and not having a very fun time of it

    Tried searching here but no joy, can anyone whack the relevant code down?

    Thanks

  2. #2
    SitePoint Guru siphilp's Avatar
    Join Date
    Nov 2001
    Location
    Fife, Scotland
    Posts
    663
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Morning blues

    Afternoon,
    Instead of trying to write a function that determines whether or not a radiobutton is checked or not etc etc. Why not set one of the radiobuttons as checked upon the page loading?


    regards


    Si Philp

  3. #3
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because from a data standpoint you will get an incredibly amount of irrelevant data as you'll never truly be sure if the user meant to check that box, or if he didn't see it, didn't both to read, etc.

    glenplake, you're looking for: document.formname.buttonname.isChecked()

    I believe... I'll get dhtmlgod over here for you
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  4. #4
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Close, its
    document.formname.buttonname.checked


  5. #5
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    See? No problem
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  6. #6
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks all

    Decided to work on something else as my monitor was in danger of having its Warranty expired, but thats great! so ill get back to it with that

  7. #7
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, Let me first say that Im not exactly good at javascript, terrible in fact, I am trying to recify this by using a big fat book, next to my to create scripts rather than use cut and paste scripts of the net.

    This usually works, however, even with the correct expression thats been given to me Im having trouble.

    Basically, I have 3 radios, and I want js to first check that one of them has been selected, and if that staement is true, then carry out the form action, otherwise, give the user an alert box, and not carry out the form action.

    The code I am trying things on is as follows:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function submitForm() {
      if (document.firstForm.format.checked==false);
      	window.alert("Please Select an option")
    }
    // -->
    </SCRIPT>
    </head>
    <body>
    <FORM METHOD="post" ACTION="mailto:dmorgan@temenos.com" NAME="firstForm" ID="firstForm" ENCTYPE="text/plain" onSubmit="submitForm">
    <INPUT TYPE="radio" NAME="format" VALUE="Excellent"> EXCELLENT
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Average"> AVERAGE
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Gash"> POOR<BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Submit" WIDTH="15" HEIGHT="40">
    </FORM>
    </body>
    </html>
    I know its not pretty and is probably riddled with syntax problem and omissions!

    D, Jeremy, any suggestions!

  8. #8
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Give this a whirl

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function submitForm(loc,thisform) 
    {
    	if (loc.checked==false)
    	{
    		window.alert("Please Select an option");
    	}
    	else
    	{
    		thisform.submit();
    	}		
    }
    // -->
    </SCRIPT>
    </head>
    <body>
    <FORM METHOD="post" ACTION="mailto:dmorgan@temenos.com" NAME="firstForm" ID="firstForm" ENCTYPE="text/plain" onSubmit="submitForm(this.form.format,this.form);">
    <INPUT TYPE="radio" NAME="format" VALUE="Excellent"> EXCELLENT
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Average"> AVERAGE
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Gash"> POOR<BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Submit" WIDTH="15" HEIGHT="40">
    </FORM>
    </body>
    </html>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  9. #9
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It doesnt like

    "this.form.format"


  10. #10
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    function submitForm(loc) 
    {
    	if (loc.format.checked==false)
    	{
    		window.alert("Please Select an option");
    	}
    	else
    	{
    		loc.submit();
    	}		
    }
    // -->
    </SCRIPT>
    </head>
    <body>
    <FORM METHOD="post" ACTION="mailto:dmorgan@temenos.com" NAME="firstForm" ID="firstForm" ENCTYPE="text/plain" onSubmit="submitForm(this.form);">
    <INPUT TYPE="radio" NAME="format" VALUE="Excellent"> EXCELLENT
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Average"> AVERAGE
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Gash"> POOR<BR>
    <INPUT TYPE="submit" NAME="submit" VALUE="Submit" WIDTH="15" HEIGHT="40">
    </FORM>
    </body>
    </html>
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  11. #11
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope! Now its doesnt like "format" here:

    if (loc.format.checked==false)

    The plus pointis, that I understand exactly what you are trying to do here

  12. #12
    SitePoint Wizard silver trophy Jeremy W.'s Avatar
    Join Date
    Jun 2001
    Location
    Toronto, Canada
    Posts
    9,123
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hmm... Interesting... I've used this method a hundred times over. My thought is that perhaps format is a reserved word... Try format2 as the name for the fileds, and change the appropriate JS to fit ...

    D?! HELP!
    SVP Marketing, SoCast SRM
    Personal blog: Strategerize
    Twitter: @jeremywright

  13. #13
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well its not a reserved word issue. As i tried completely random and obscure names.

    /me searches for that "Pulls out hair" Smiley! <-- but settles for this one!

  14. #14
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gimme 2 mins...

  15. #15
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    <SCRIPT LANGUAGE="JavaScript1.2">
    <!--
    var chk = 0
    function submitForm() 
    {
    	formatCheck = document.forms[0].format
    	txt=""
    	for (i = 0; i<formatCheck.length; ++ i)
    	{
    			if (formatCheck[i].checked)
    		{
    	 		chk = chk + 1
    		}
    	}
    	if (chk != 0) {
    		document.firstForm.submit();
    	}else{
    		alert('Please select one');
    	}
    }
    // -->
    </SCRIPT>
    </head>
    <body>
    <FORM METHOD="post" ACTION="mailto:dmorgan@temenos.com" NAME="firstForm">
    <INPUT TYPE="radio" NAME="format" VALUE="Excellent"> EXCELLENT
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Average"> AVERAGE
    <BR><INPUT TYPE="radio" NAME="format" VALUE="Gash"> POOR<BR>
    <INPUT TYPE="button" NAME="chkRadio" VALUE="Submit" WIDTH="15" HEIGHT="40"  onClick="submitForm();">
    </FORM>
    </body>
    </html>
    Sorry took so long, had a meeting.


  16. #16
    Gone!
    Join Date
    Aug 2001
    Location
    Witty Location Parody
    Posts
    3,889
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks D! and everyone


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
  •