?
Solved

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

Posted on 2004-04-22
10
Medium Priority
?
340 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
What You Need to Know when Searching for a Webhost Provider
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

801 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