redirecting form based on radio button values

This is a discussion on "redirecting form based on radio button values" within the JavaScript Forum section. This forum, and the thread "redirecting form based on radio button values are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Oct 9th, 2007, 08:51
Junior Member
Join Date: Jul 2006
Location: London
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
redirecting form based on radio button values

I am using the following function to alter visibility of proceed links to move from one step in a form to another based on text field validation:

Code: Select all
function toggleProceed(fields, proceedLink)
{

// Loop through the array of id's to check
  for (i = 0; i < fields.length; i++)
      if (document.getElementById(fields[i]).value == "")
       
      {   // if no value, the reset link to hidden and exit from function
          document.getElementById(proceedLink).style.visibility = 'hidden';
          return;
       }

   // If we made it here we can show the link
   document.getElementById(proceedLink).style.visibility = 'visible';

}
it is used in the form like this:

Code: Select all
<input type="text" size="53" id="requestename" name="requestname" maxlength="255" value="" onkeyup="toggleProceed(new Array('requestename'), 'proceed')" />
<a class="panelProceed" href="javascript:void(0)" id="proceed" style="visibility:hidden;" onmousedown="toggleDiv('requestName'); toggleDiv('requestCat')">next &gt;&gt;</a>
now I have another section in the same form containing a radio group:

Code: Select all
<input type="radio" id="work_type_im" name="Type of work" class="checkbox" title="select instant messaging" /> 
        <label for="work_type_im">Instant Messaging</label> &nbsp;&nbsp;
                        
        <input type="radio" id="work_type_video" name="Type of work" class="checkbox" title="select web cam" /> 
        <label for="work_type_video">Video Chat</label> &nbsp;&nbsp;
                        
        <input type="radio" id="work_type_audio" name="Type of work" class="checkbox" title="select audio chat" /> 
        <label for="work_type_audio">Audio Chat</label> &nbsp;&nbsp;
                        
        <input type="radio" id="work_type_text" name="Type of work" class="checkbox" title="select text" /> 
        <label for="work_type_text">Text Chat</label> &nbsp;&nbsp;
                        
        <input type="radio" id="work_type_online" name="Type of work" class="checkbox" title="select online work" /> 
        <label for="work_type_text">Online Work</label>
<a class="panelProceed" href="javascript:void(0)" onmousedown="toggleDiv('requestMed'); toggleDiv('requestDate')" style="visibility:hidden;" >next &gt;&gt;</a>
If the work_type_im is clicked, I want to have the variable 'requestDate' change to another variable so the user is redirected to another section in the form. If they click any other radio button in the group, the default 'requestDate' is retained.

So I guess what I need to is be able to change that variable on the fly if they select that specific radio button...

?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Oct 9th, 2007, 09:02
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

You could try adding this to all the radio buttons.

onclick="updateToggleDive('nameOfDiv')";

so you on the work_type_im you can add the name of the replacement to 'requestDate' where 'nameOfDIv' is and put 'requestDate' on all the others.

Give the proceed link an id of "proceedLink" or something

Then after the radios add this

Code: Select all
<script type="text/javascript">
function updateToggleDiv(divName)
{
    document.getElementById('proceedDiv').onmousedown = function () {
    toggleDiv('requestMed'); 
    toggleDiv(divName);
}
</script>
Cheers,
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Oct 9th, 2007, 09:35
Junior Member
Join Date: Jul 2006
Location: London
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

It doesn't seem to be working although I may have misunderstood your suggestion. This is how I have interpreted:

Code: Select all
<input type="radio" id="work_type_im" name="Type of work" class="checkbox" title="select instant messaging" onclick="updateToggleDiv('requestMax')"; /> 
<label for="work_type_im">Instant Messaging</label> &nbsp;&nbsp;
                        
<input type="radio" id="work_type_video" name="Type of work" class="checkbox" title="select web cam" onclick="updateToggleDiv('requestDate')"; /> 
<label for="work_type_video">Video Chat</label> &nbsp;&nbsp;
                        
<input type="radio" id="work_type_audio" name="Type of work" class="checkbox" title="select audio chat" onclick="updateToggleDiv('requestDate')"; /> 
<label for="work_type_audio">Audio Chat</label> &nbsp;&nbsp;
                        
<input type="radio" id="work_type_text" name="Type of work" class="checkbox" title="select text" onclick="updateToggleDiv('requestDate')"; /> 
<label for="work_type_text">Text Chat</label> &nbsp;&nbsp;
                        
<input type="radio" id="work_type_online" name="Type of work" class="checkbox" title="select online work" onclick="updateToggleDiv('requestDate')"; />

<script type="text/javascript">
function updateToggleDiv(divName)
{
    document.getElementById('proceedDiv').onmousedown = function () {
    toggleDiv('requestMed'); 
    toggleDiv(divName);
}
</script>

<a class="panelProceed" id="proceedLink" href="javascript:void(0)" onmousedown="toggleDiv('requestMed'); toggleDiv('requestDate')" style="visibility:hidden;" >next &gt;&gt;</a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Oct 9th, 2007, 09:38
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

Need to fix this line, it has proceedDiv which doesn't exist

Code: Select all
document.getElementById('proceedLink').onmousedown = function () {
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Oct 9th, 2007, 09:52
Junior Member
Join Date: Jul 2006
Location: London
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

Quote:
Originally Posted by Rakuli View Post
Need to fix this line, it has proceedDiv which doesn't exist

Code: Select all
document.getElementById('proceedLink').onmousedown = function () {
I have fixed this but it is still not altering that toggleDiv variable. I realise there are a couple more errors in the markup that I have fixed, such as an ';' in the wrong place in the radio buttons and I also have not added the toggleProceed function yet.

Aside from these I cannot seem to figure out where its going wrong...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Oct 9th, 2007, 09:59
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

Woops

Didn't close the function

Code: Select all
<script type="text/javascript">
function updateToggleDiv(divName)
{
    document.getElementById('proceedLink').onmousedown = function () 
   {
    toggleDiv('requestMed'); 
    toggleDiv(divName);
    }
}
That should be okay **Strokes chin and makes contemplative noise.. "hmm" **
</script>
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Oct 9th, 2007, 10:24
Junior Member
Join Date: Jul 2006
Location: London
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

Quote:
Originally Posted by Rakuli View Post
Woops

Didn't close the function

Code: Select all
<script type="text/javascript">
function updateToggleDiv(divName)
{
    document.getElementById('proceedLink').onmousedown = function () 
   {
    toggleDiv('requestMed'); 
    toggleDiv(divName);
    }
}
That should be okay **Strokes chin and makes contemplative noise.. "hmm" **
</script>
Ah thanks, that worked a treat!

Now since I have redirected the user to another section in the form, if they wish to use the back button, I need to also populate that backLink with the variable to take them back to the step with the radio group... Would I just do this?

Code: Select all
<script type="text/javascript">
function updateToggleDiv(divName)
{
    document.getElementById('proceedLink').onmousedown = function () 
   {
    toggleDiv('requestMed'); 
    toggleDiv(divName);
    }
    document.getElementById('backLink').onmousedown = function () 
   {
    toggleDiv(divName); 
    toggleDiv('requestDel');
    }
}
</script>
and then in the redirected section, do this:

Code: Select all
<a class="panelBack" href="javascript:void(0)" id="backLink" onmousedown="toggleDiv('requestMax'); toggleDiv('requestDel')">&lt;&lt; back</a>
?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Oct 9th, 2007, 10:26
Rakuli's Avatar
SuperMember

SuperMember
Join Date: Sep 2007
Location: Australia
Age: 24
Posts: 956
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: redirecting form based on radio button values

Yup, that would do it

Glad it works
Last Blog Entry: The wannabe juggler's quest (Oct 27th, 2007)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] large radio button form submit chriscant JavaScript Forum 7 Oct 25th, 2007 09:03
Any way to use an image for a radio button? masonbarge Web Page Design 23 Jan 6th, 2007 09:06
Help needed with creating a radio button form sing2trees PHP Forum 1 Nov 13th, 2006 05:52
Setting Form Values to Previously Entered Values masonbarge PHP Forum 6 Oct 17th, 2006 17:36
problem with radio button in form validation augustus_emperor JavaScript Forum 1 Apr 22nd, 2004 13:08


All times are GMT. The time now is 03:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42