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
Solved

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

Posted on 2004-04-22
10
335 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

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…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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