Solved

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

Posted on 2004-04-22
10
337 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

 
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
 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

729 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