Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-22
10
Medium Priority
?
342 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
Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

609 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