Solved

Input hidden field name changes in accordance to previous radio button answer

Posted on 2004-04-22
10
332 Views
Last Modified: 2013-12-24
How do I code the following:

If a previous radio button is clicked then I want an input type hidden fild named "required" is the previous button is not checked or unchecked the the name of the hidden field will be "not_req". I'm not asking for the hidden field value I'm saying "name"

I'm using javascript and coldfusion

Everything happens in the same page
0
Comment
Question by:gaby22
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 17

Expert Comment

by:anandkp
ID: 10892014
I doubt ... thou i wonder why u wanna do this ... why cldnt u just change the value in the hidden field & use it accordingly ...
or just chk for the radio button being defined in the submitted page or not !
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10892093
Why would you want to change the name of the hidden field? WHat is the value then?  And how would you know in cold fusion what to look for?  If you know what to look for based off of the radio button then why even have the hidden field at all?  Just use the status of the radio button.

But, I guess you could do this if you really wanted to.  You would have to enclose the field in a span with an id

<span id="myhiddenfield"><input type="hidden" name="required" value=""></span>

Then in the javascript you could create a new input with the new name:

tempInput = document.createElement("INPUT");
tempInput.type = "HIDDEN";
tempInput.name = "not_required";
tempInput.value = "";

And then place it inside the span.
0
 

Author Comment

by:gaby22
ID: 10892111
I have a generic funtion that validates required fields when the submit button is clicked. It works by using a hidden field per each field to be validadted: <input type="hidden" name="r_fieldtovalidate" value="Please answer question1"> If one of the radio button on the form is clicked then I don't want this validation to occur for quiestion1
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10892259
So really this is not a cold fusion question at all but is a javascript question.

So what you really want is to just use the following :

<span id="myhiddenfield"><input type="hidden" name="required" value=""></span>

And then you need the onChange of the radio button to call a function that determines what input to put there :

If checked:
document.getElementById('myhiddenfield').innerHTML = "<input type='hidden' name='required' value=''>";

If not checked :
document.getElementById('myhiddenfield').innerHTML = "<input type='hidden' name='not_req' value='Please enter a value'>";
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 10892270
whoops - I mixed up the two values for the hidden inputs.

It should have been :

If checked:
document.getElementById('myhiddenfield').innerHTML = "<input type='hidden' name='required' value='Please enter a value'>";

If not checked :
document.getElementById('myhiddenfield').innerHTML = "<input type='hidden' name='not_req' value=''>";
0
Network it in WD Red

There's an industry-leading WD Red drive for every compatible NAS system to help fulfill your data storage needs. With drives up to 8TB, WD Red offers a wide array of solutions for customers looking to build the biggest, best-performing NAS storage solution.  

 
LVL 17

Expert Comment

by:anandkp
ID: 10895888
Why dont u controll the validation on the basis of the radio button being defined or not ?
if its defined - u dont need to validate ...
0
 
LVL 11

Accepted Solution

by:
hart earned 250 total points
ID: 10897432
try this out and see

<CFIF IsDefined('not_req')>
    <CFOUTPUT>#form.not_req#</CFOUTPUT>
</CFIF>

<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
      function callme()
      {      
            alert(document.frm.elements[2].name)
            document.frm.elements[2].name = "not_req";
            alert(document.frm.elements[2].name)
      }      
//-->
</SCRIPT>
</HEAD>
<BODY>
      <FORM NAME="frm" METHOD="post" ACTION="try.cfm">
            <INPUT TYPE="Radio" NAME="checkme" VALUE="1" ONCLICK="callme()">
             <INPUT TYPE="Radio" NAME="checkme" VALUE="2" ONCLICK="callme()">
             <input type="hidden" name="r_fieldtovalidate" value="Please answer question1">            
             <input TYPE="submit" VALUE="Sub Me">
      </FORM>
</BODY>
</HTML>

What i am doing is on click of the radio button i am changing the name of the hidden field to "not_req"
and if u click on submit it submits to the same page and u will get form.not_req defined in cf

i hope this what u want..

Regards
Hart
0
 
LVL 35

Assisted Solution

by:mrichmon
mrichmon earned 250 total points
ID: 10900447
While I don't think that gaby's method is the best way to go I do understand what he is doing and why.

The reason that he is not using the radio button to control validation is that he is not writing the validation script.  He is using a script that will auto validate any field that has a corresponding hidden field.

So the only way to force the script not to validate is to change the name of the hidden variable.

I thought of an even better way than the one I posted above - use an id in the input itself

<input type="hidden" name="required" id="myhiddenfield" value="Please test">

Then
document.getElementById('myhiddenfield').name = "not_req";
0
 
LVL 11

Expert Comment

by:hart
ID: 10936425
gaby, did u find any solution...
0
 

Author Comment

by:gaby22
ID: 11031131
Althought the solution I found was not excatly from these aswers I got some ideas from here to figure it out..What I did was assign fake values using a javascript functions once the user selected the answer that didn't requiered further asnwers and reset these vales if the user changed the answer back to one that did require further answers.

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now