Jump to content

Form Validation


Zergman

Recommended Posts

Not sure if this is the right area, my apologies if it isn't.

 

On my form, I have a couple radio buttons.  I don't have them preselected so I need to validate them when the form is submitted.

 

<form action="<?php echo $editFormAction; ?>" method="post" name="myform" id="myform" onsubmit="MM_validateForm('Agent_TID','','RisNum');return document.MM_returnValue">

AB<input name="radio" type="radio" id="abradio" value="AB" />
BC<input type="radio" name="radio" id="bcradio" value="BC" />

 

I found a bunch of javascript that would do it but would rather not have to use java if not necessary.

 

Any help would be appreciated.

Link to comment
Share on other sites

quick an to the point reply:

try pointing the form action to a file with nothing but this:

die(var_dump($_POST));

and compare radio button values when checked and when not checked.

 

and here's from my compromised memory: since they are in the same "group" (they have the same name property) the POST value for that particular name will = the value of the selected radio button, or "" if none are selected.

 

ps - i find it kinda odd that you're ok with using Dreamweaver pre-made JS to achieve rollover images but dont wanna use JS to validate the form??

 

ideally you should validate both client AND server side (if client has JS it'll spare you the extra trip back and forth)

 

-Alex

Link to comment
Share on other sites

Thanks for the quick reply.

 

Don't get me wrong, I don't mind using javascript to validate the radio buttons if necessary but what Dreamweaver does behind the scenes is up to it hehe.

 

P.S. I still use Dreamweaver to help me since i'm all self taught, but passed a mile stone yesterday when I went notepad++ 100% since I forgot my laptop at home.  Learned a lot!

 

 

Link to comment
Share on other sites

nevermind, found one that works good.

 

http://www.felgall.com/javatip2.htm

 

Just need a tid bit of advise though.

 

I just need one other field validated and I don't know how to modify this code to validate it.  Damn my newbish brain.

 

Here's the field I need validated other than the radio buttons.

<input name="Agent_TID" type="text" class="inputbox" id="Agent_TID" value="" size="15" maxlength="6" />

 

Here's the script

function valbutton(thisform) {
// place any other field validations that you require here
// validate myradiobuttons
myOption = -1;
for (i=thisform.myradiobutton.length-1; i > -1; i--) {
if (thisform.myradiobutton[i].checked) {
myOption = i; i = -1;
}
}
if (myOption == -1) {
alert("You must select a radio button");
return false;
}

alert("You selected button number " + myOption
+ " which has a value of "
+ thisform.myradiobutton[myOption].value);

// place any other field validations that you require here
thisform.submit(); // this line submits the form after validation
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.